本文整理匯總了Golang中github.com/koding/logging.Logger類的典型用法代碼示例。如果您正苦於以下問題:Golang Logger類的具體用法?Golang Logger怎麽用?Golang Logger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Logger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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()
}
示例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()
}
示例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
}
示例4: NewStatus
func NewStatus(log logging.Logger, mg MachineGetter) *Status {
return &Status{
Log: log.New("status"),
MachineGetter: mg,
HTTPClient: defaultHTTPClient,
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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,
}
}
示例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,
}
}
示例11: NewPagerduty
func NewPagerduty(pc *PagerdutyConfig, log logging.Logger) (*Pagerduty, error) {
return &Pagerduty{
publicURL: pc.PublicURL,
integrationURL: pc.IntegrationURL,
log: log.New(PAGERDUTY),
}, nil
}
示例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(),
}
}
示例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
}
示例14: newCommand
func newCommand(cwd string, log logging.Logger) *command {
cmd := &command{
cwd: cwd,
}
if log != nil {
cmd.log = log.New(cwd)
}
return cmd
}
示例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
}