本文整理汇总了Golang中github.com/koding/logging.Logger类的典型用法代码示例。如果您正苦于以下问题:Golang Logger类的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Join
// Join copies data between local and remote connections.
// It reads from one connection and writes to the other.
// It's a building block for ProxyFunc implementations.
func Join(local, remote net.Conn, log logging.Logger) {
var wg sync.WaitGroup
wg.Add(2)
transfer := func(side string, dst, src net.Conn) {
log.Debug("proxing %s -> %s", src.RemoteAddr(), dst.RemoteAddr())
n, err := io.Copy(dst, src)
if err != nil {
log.Error("%s: copy error: %s", side, err)
}
if err := src.Close(); err != nil {
log.Debug("%s: close error: %s", side, err)
}
// not for yamux streams, but for client to local server connections
if d, ok := dst.(*net.TCPConn); ok {
if err := d.CloseWrite(); err != nil {
log.Debug("%s: closeWrite error: %s", side, err)
}
}
wg.Done()
log.Debug("done proxing %s -> %s: %d bytes", src.RemoteAddr(), dst.RemoteAddr(), n)
}
go transfer("remote to local", local, remote)
go transfer("local to remote", remote, local)
wg.Wait()
}
开发者ID:,项目名称:,代码行数:35,代码来源:
示例2: UninstallCommand
// UninstallCommand configures the Uninstall struct and calls it based on the
// given codegangsta/cli context.
//
// TODO: remove all artifacts, ie bolt db, ssh keys, kd etc.
func UninstallCommand(c *cli.Context, log logging.Logger, _ string) (string, int) {
warnings := []string{}
// Ensure /etc/kite/kite.key is migrated to konfig.bolt before
// old klient gets uninstalled. The endpoint/config package
// performs lazy migrations, so it's enough to call any of
// its methods and disregard the result.
_ = configcli.List()
s, err := newService(nil)
if err != nil {
log.Warning("Failed creating Service for uninstall. err:%s", err)
warnings = append(warnings, FailedUninstallingKlientWarn)
}
uninstaller := &Uninstall{
ServiceUninstaller: s,
KlientName: config.KlientName,
KlientctlName: config.Name,
KlientctlPath: filepath.Join(KlientctlDirectory, KlientctlBinName),
// TODO: Store the klient directory structure(s) somewhere
KlientParentDirectory: "/opt",
KlientDirectory: "kite/klient",
KlientFilename: "klient",
KlientshFilename: "klient.sh",
remover: os.Remove,
warnings: warnings,
log: log,
}
return uninstaller.Uninstall()
}
开发者ID:,项目名称:,代码行数:36,代码来源:
示例3: NewMachine
// NewMachine initializes a new Machine struct with any internal vars created.
func NewMachine(meta MachineMeta, log logging.Logger, t Transport) (*Machine, error) {
log = MachineLogger(meta, log)
// Create our Pingers, to be used in the PingTrackers
kitePinger := kitepinger.NewKitePinger(t)
httpPinger, err := kitepinger.NewKiteHTTPPinger(meta.URL)
if err != nil {
log.Error(
"Unable to create HTTPPinger from meta.URL. url:%s, err:%s", meta.URL, err,
)
return nil, err
}
m := &Machine{
MachineMeta: meta,
Log: log,
KiteTracker: kitepinger.NewPingTracker(kitePinger),
HTTPTracker: kitepinger.NewPingTracker(httpPinger),
Transport: t,
discover: discover.NewClient(),
mountLocker: util.NewMutexWithState(),
}
m.discover.Log = m.Log.New("discover")
// Start our http pinger, to give online/offline statuses for all machines.
m.HTTPTracker.Start()
return m, nil
}
开发者ID:koding,项目名称:koding,代码行数:31,代码来源:machine.go
示例4: NewStatus
func NewStatus(log logging.Logger, mg MachineGetter) *Status {
return &Status{
Log: log.New("status"),
MachineGetter: mg,
HTTPClient: defaultHTTPClient,
}
}
开发者ID:koding,项目名称:koding,代码行数:7,代码来源:status.go
示例5: NewAddresses
// NewAddresses fetches EC2 IP address list from each region.
//
// If log is nil, defaultLogger is used instead.
func NewAddresses(clients *amazon.Clients, log logging.Logger) *Addresses {
if log == nil {
log = defaultLogger
}
a := newAddresses()
var wg sync.WaitGroup
var mu sync.Mutex // protects a.m
for region, client := range clients.Regions() {
wg.Add(1)
go func(region string, client *amazon.Client) {
defer wg.Done()
addresses, err := client.Addresses()
if err != nil {
log.Error("[%s] fetching IP addresses error: %s", region, err)
return
}
log.Info("[%s] fetched %d addresses", region, len(addresses))
var ok bool
mu.Lock()
if _, ok = a.m[client]; !ok {
a.m[client] = addresses
}
mu.Unlock()
if ok {
panic(fmt.Errorf("[%s] duplicated client=%p: %+v", region, client, addresses))
}
}(region, client)
}
wg.Wait()
return a
}
开发者ID:koding,项目名称:koding,代码行数:34,代码来源:addresses.go
示例6: NewMultiInstances
// NewMultiInstances fetches EC2 instance list from each region.
func NewMultiInstances(clients *amazon.Clients, log logging.Logger) *MultiInstances {
if log == nil {
log = defaultLogger
}
var m = newMultiInstances()
var wg sync.WaitGroup
var mu sync.Mutex // protects m.m
for region, client := range clients.Regions() {
wg.Add(1)
go func(region string, client *amazon.Client) {
defer wg.Done()
instances, err := client.Instances()
if err != nil {
log.Error("[%s] fetching instances error: %s", region, err)
return
}
log.Info("[%s] fetched %d instances", region, len(instances))
i := make(Instances, len(instances))
for _, instance := range instances {
i[aws.StringValue(instance.InstanceId)] = instance
}
var ok bool
mu.Lock()
if _, ok = m.m[client]; !ok {
m.m[client] = i
}
mu.Unlock()
if ok {
panic(fmt.Errorf("[%s] duplicated client=%p: %+v", region, client, i))
}
}(region, client)
}
wg.Wait()
return m
}
开发者ID:koding,项目名称:koding,代码行数:36,代码来源:multiinstances.go
示例7: CreateMetrics
func CreateMetrics(appName string, log logging.Logger, outputMetrics bool) (*kodingmetrics.Metrics, *kodingmetrics.DogStatsD) {
metric := kodingmetrics.New(appName)
// if outputMetrics, do print output to the console
if outputMetrics {
// change those loggers
// https://github.com/rcrowley/go-metrics/blob/37df06ff62a7d8b4473b48d355008c838da87561/log.go
// get those numbers from config
// output metrics every 1 minutes
go metrics.Log(metric.Registry, 6e10, slog.New(os.Stderr, "metrics: ", slog.Lmicroseconds))
}
// Left here for future reference
// for Mac
syslogPath := "/var/run/syslog"
if runtime.GOOS != "darwin" {
// for linux
syslogPath = "/dev/log"
}
w, err := syslog.Dial("unixgram", syslogPath, syslog.LOG_INFO, "socialapi-metrics")
if err != nil {
log.Error("Err while initing syslog for metrics, metrics wont be in the syslog %s", err.Error())
} else {
go metrics.Syslog(metric.Registry, 30e10, w)
}
statsd, err := kodingmetrics.NewDogStatsD(appName)
if err == nil {
go kodingmetrics.Collect(metric.Registry, statsd, 24e10)
}
return metric, statsd
}
开发者ID:,项目名称:,代码行数:35,代码来源:
示例8: MachineListCommand
// MachineListCommand returns list of remote machines belonging to the user or
// that can be accessed by her.
func MachineListCommand(c *cli.Context, log logging.Logger, _ string) (int, error) {
// List command doesn't support identifiers.
idents, err := getIdentifiers(c)
if err != nil {
return 1, err
}
if err := identifiersLimit(idents, 0, 0); err != nil {
return 1, err
}
opts := &machine.ListOptions{
Log: log.New("machine:list"),
}
infos, err := machine.List(opts)
if err != nil {
return 1, err
}
if c.Bool("json") {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", "\t")
enc.Encode(infos)
return 0, nil
}
tabFormatter(os.Stdout, infos)
return 0, nil
}
开发者ID:,项目名称:,代码行数:31,代码来源:
示例9: NewErrorCommand
func NewErrorCommand(stdout io.Writer, log logging.Logger, err error, msg string) *ErrorCommand {
return &ErrorCommand{
Stdout: util.NewFprint(stdout),
Log: log.New("errorCommand"),
Message: msg,
Error: err,
}
}
开发者ID:,项目名称:,代码行数:8,代码来源:
示例10: NewRecordManager
// NewRecordManager creates a RecordManager
func NewRecordManager(session *session.Session, log logging.Logger, region string, hostedZoneConf HostedZone) *RecordManager {
return &RecordManager{
route53: route53.New(session),
log: log.New("recordmanager"),
region: region,
hostedZoneConf: hostedZoneConf,
}
}
开发者ID:,项目名称:,代码行数:9,代码来源:
示例11: NewPagerduty
func NewPagerduty(pc *PagerdutyConfig, log logging.Logger) (*Pagerduty, error) {
return &Pagerduty{
publicURL: pc.PublicURL,
integrationURL: pc.IntegrationURL,
log: log.New(PAGERDUTY),
}, nil
}
开发者ID:,项目名称:,代码行数:8,代码来源:
示例12: NewDefaultHealthChecker
func NewDefaultHealthChecker(l kodinglogging.Logger) *HealthChecker {
return &HealthChecker{
Log: l.New("HealthChecker"),
HTTPClient: defaultClient,
LocalKlientAddress: config.Konfig.Endpoints.Klient.Private.String(),
KontrolAddress: config.Konfig.Endpoints.Kontrol().Public.String(),
InternetCheckAddress: config.Konfig.Endpoints.KlientLatest.Public.String(),
TunnelKiteAddress: config.Konfig.Endpoints.Tunnel.Public.String(),
}
}
开发者ID:,项目名称:,代码行数:10,代码来源:
示例13: RestartCommand
// RestartCommand stops and starts klient. If Klient is not running to begin
// with, it *just* starts klient.
func RestartCommand(c *cli.Context, log logging.Logger, _ string) int {
if len(c.Args()) != 0 {
cli.ShowCommandHelp(c, "restart")
return 1
}
log = log.New("cmd:restart")
s, err := newService(nil)
if err != nil {
log.Error("Error creating Service. err:%s", err)
fmt.Println(GenericInternalNewCodeError)
return 1
}
fmt.Printf("Restarting the %s, this may take a moment...\n", config.KlientName)
klientWasRunning := IsKlientRunning(config.Konfig.Endpoints.Klient.Private.String())
if klientWasRunning {
// If klient is running, stop it, and tell the user if we fail
if err := s.Stop(); err != nil {
log.Error("Error stopping Service. err:%s", err)
fmt.Println(FailedStopKlient)
return 1
}
} else {
// If klient appears to not be running, try to stop it anyway. However,
// because it may not actually be running, don't inform the user if we fail here.
s.Stop()
}
err = WaitUntilStopped(config.Konfig.Endpoints.Klient.Private.String(), CommandAttempts, CommandWaitTime)
if err != nil {
log.Error(
"Timed out while waiting for Klient to start. attempts:%d, err:%s",
5, err,
)
fmt.Println(FailedStopKlient)
return 1
}
if klientWasRunning {
fmt.Println("Stopped successfully.")
}
// No UX message needed, startKlient will do that itself.
if err := startKlient(log, s); err != nil {
log.Error("failed to start klient: %s", err)
return 1
}
fmt.Printf("Successfully restarted %s\n", config.KlientName)
return 0
}
开发者ID:,项目名称:,代码行数:57,代码来源:
示例14: newCommand
func newCommand(cwd string, log logging.Logger) *command {
cmd := &command{
cwd: cwd,
}
if log != nil {
cmd.log = log.New(cwd)
}
return cmd
}
开发者ID:koding,项目名称:vagrantutil,代码行数:11,代码来源:command.go
示例15: NewPivotal
func NewPivotal(pc *PivotalConfig, log logging.Logger) (*Pivotal, error) {
if pc.ServerURL == "" {
pc.ServerURL = PivotalServerURL
}
return &Pivotal{
serverURL: pc.ServerURL,
publicURL: pc.PublicURL,
integrationURL: pc.IntegrationURL,
log: log.New(PIVOTAL),
}, nil
}
开发者ID:,项目名称:,代码行数:12,代码来源:
示例16: NewLifeCycle
// NewLifeCycle creates a new lifecycle management system, everything begins
// with an autoscaling resource, we are listening to any change on that
// resource, to be able to listen them we are attaching a notification
// configuration to given autoscaling resource, notification configuration works
// with a TopicARN, which is basically a SNS Topic, to be able to listen from a
// Topic ARN we need a SQS, SQS is attached to Notification Topic and configured
// to pass events as soon as they occur, it also has re- try mechanism. One
// event only be handled by one manager, there wont be any race condition on
// processing that particular message. Manager is idempotent, if any given
// resource doesnt exist in the given AWS system, it will create or re-use the
// previous ones
func NewLifeCycle(session *session.Session, log logging.Logger, asgName string) *LifeCycle {
return &LifeCycle{
closed: false,
closeChan: make(chan chan struct{}),
ec2: ec2.New(session),
sqs: sqs.New(session),
sns: sns.New(session),
autoscaling: autoscaling.New(session),
asgName: &asgName,
log: log.New("lifecycle"),
}
}
开发者ID:,项目名称:,代码行数:23,代码来源:
示例17: fetchHostedZone
// fetchHostedZone fetches all hosted zones from account and iterates over them
// until it finds the respective one
func (r *RecordManager) fetchHostedZone(hostedZoneLogger logging.Logger) error {
const maxIterationCount = 100
iteration := 0
// for pagination
var nextMarker *string
// try to get our hosted zone
for {
// just be paranoid about remove api calls, dont harden too much
if iteration == maxIterationCount {
return errors.New("iteration terminated")
}
log := hostedZoneLogger.New("iteration", iteration)
iteration++
log.Debug("Fetching hosted zone")
listHostedZonesResp, err := r.route53.ListHostedZones(
&route53.ListHostedZonesInput{
Marker: nextMarker,
}, // we dont have anything to filter
)
if err != nil {
return err
}
if listHostedZonesResp == nil || listHostedZonesResp.HostedZones == nil {
return errors.New("malformed response - reponse or hosted zone is nil")
}
for _, hostedZone := range listHostedZonesResp.HostedZones {
if hostedZone == nil || hostedZone.CallerReference == nil {
continue
}
if *hostedZone.CallerReference == r.hostedZoneConf.CallerReference {
r.hostedZone = hostedZone
return nil
}
}
// if our result set is truncated we can try to fetch again, but if we
// reach to end, nothing to do left
if listHostedZonesResp.IsTruncated == nil || !*listHostedZonesResp.IsTruncated {
return errHostedZoneNotFound
}
// assign next marker
nextMarker = listHostedZonesResp.NextMarker
}
}
开发者ID:,项目名称:,代码行数:55,代码来源:
示例18: New
func New(log logging.Logger, client algoliasearch.Client, indexSuffix string) *Controller {
// TODO later on listen channel_participant_added event and remove this koding channel fetch
c := models.NewChannel()
q := request.NewQuery()
q.GroupName = "koding"
q.Name = "public"
q.Type = models.Channel_TYPE_GROUP
channel, err := c.ByName(q)
if err != nil {
log.Error("Could not fetch koding channel: %s:", err)
}
var channelId string
if channel.Id != 0 {
channelId = strconv.FormatInt(channel.Id, 10)
}
controller := &Controller{
log: log,
client: client,
indexes: &IndexSet{
IndexTopics: &IndexSetItem{
Index: client.InitIndex(IndexTopics + indexSuffix),
Settings: &Settings{
// empty slice means all properties will be searchable
AttributesToIndex: []string{},
},
},
IndexAccounts: &IndexSetItem{
Index: client.InitIndex(IndexAccounts + indexSuffix),
Settings: &Settings{
AttributesToIndex: []string{
"nick",
"email",
"firstName",
"lastName",
"_tags",
},
UnretrievableAttributes: []string{"email"},
},
},
IndexMessages: &IndexSetItem{
Index: client.InitIndex(IndexMessages + indexSuffix),
Settings: &Settings{
AttributesToIndex: []string{},
},
},
},
kodingChannelId: channelId,
}
return controller
}
开发者ID:,项目名称:,代码行数:53,代码来源:
示例19: New
// New creates a new terraformer
func New(conf *Config, log logging.Logger) (*Terraformer, error) {
ls, err := storage.NewFile(conf.LocalStorePath, log)
if err != nil {
return nil, fmt.Errorf("error while creating local store: %s", err)
}
var rs storage.Interface
if conf.AWS.Key != "" && conf.AWS.Secret != "" && conf.AWS.Bucket != "" {
s3, err := storage.NewS3(conf.AWS.Key, conf.AWS.Secret, conf.AWS.Bucket, log)
if err != nil {
return nil, fmt.Errorf("error while creating remote store: %s", err)
}
rs = s3
} else {
remotePath := filepath.Dir(conf.LocalStorePath)
if conf.AWS.Bucket != "" {
remotePath = filepath.Join(remotePath, conf.AWS.Bucket)
} else {
remotePath = filepath.Join(remotePath, filepath.Base(conf.LocalStorePath)+".remote")
}
local, err := storage.NewFile(remotePath, log)
if err != nil {
return nil, fmt.Errorf("error while creating remote store on local: %s", err)
}
log.Info("no S3 credentials, using local storage: %s", remotePath)
rs = local
}
c, err := kodingcontext.New(ls, rs, log, conf.Debug)
if err != nil {
return nil, err
}
t := &Terraformer{
Log: log,
Metrics: common.MustInitMetrics(Name),
Debug: conf.Debug,
Context: c,
Config: conf,
closeChan: make(chan struct{}),
}
t.handleSignals()
return t, nil
}
开发者ID:koding,项目名称:koding,代码行数:51,代码来源:terraformer.go
示例20: FactoryCompletion
// FactoryCompletion implements codeganstas cli.Command's bash completion field
func FactoryCompletion(factory CommandFactory, log logging.Logger, cmdName string) cli.BashCompleteFunc {
return func(c *cli.Context) {
cmd := factory(c, log, cmdName)
// If the command implements AutocompleteCommand, run the autocomplete.
if aCmd, ok := cmd.(AutocompleteCommand); ok {
if err := aCmd.Autocomplete(c.Args()...); err != nil {
log.Error(
"Autocompletion of a command encountered error. command:%s, err:%s",
cmdName, err,
)
}
}
}
}
开发者ID:,项目名称:,代码行数:16,代码来源:
注:本文中的github.com/koding/logging.Logger类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论