本文整理匯總了Golang中github.com/koding/logging.Logger.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Error方法的具體用法?Golang Logger.Error怎麽用?Golang Logger.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/koding/logging.Logger
的用法示例。
在下文中一共展示了Logger.Error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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
}
示例5: 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()
}
示例6: 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
}
示例7: setDefaults
func setDefaults(log logging.Logger) {
group, err := modelhelper.GetGroup(models.Channel_KODING_NAME)
if err != nil {
log.Error("err while fetching koding group: %s", err.Error())
return
}
log.Debug("mongo group found")
setPublicChannel(log, group)
setChangeLogChannel(log, group)
log.Info("socialApi defaults are created")
}
示例8: 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,
)
}
}
}
}
示例9: ExitErrAction
// ExitErrAction implements a cli.Command's Action field for an ExitingErrCommand
func ExitErrAction(f ExitingErrCommand, log logging.Logger, cmdName string) cli.ActionFunc {
return func(c *cli.Context) error {
exit, err := f(c, log, cmdName)
if err != nil {
log.Error("ExitErrAction encountered error. err:%s", err)
// Print error message to the user.
fmt.Fprintf(os.Stderr, "error executing %q command: %s\n", cmdName, err)
}
Close()
ExitFunc(exit)
return nil
}
}
示例10: setChangeLogChannel
func setChangeLogChannel(log logging.Logger, group *kodingmodels.Group) {
c := models.NewChannel()
selector := map[string]interface{}{
"type_constant": models.Channel_TYPE_ANNOUNCEMENT,
"group_name": models.Channel_KODING_NAME,
}
// if err is nil
// it means we already have that channel
err := c.One(bongo.NewQS(selector))
if err != nil && err != bongo.RecordNotFound {
log.Error("err while fetching changelog channel:", err.Error())
return
}
if err == bongo.RecordNotFound {
log.Error("postgres changelog couldn't found, creating it")
acc, err := createChannelOwner(group)
if err != nil {
log.Error(err.Error())
return
}
c.Name = "changelog"
c.CreatorId = acc.Id
c.GroupName = models.Channel_KODING_NAME
c.TypeConstant = models.Channel_TYPE_ANNOUNCEMENT
c.PrivacyConstant = models.Channel_PRIVACY_PRIVATE
if err := c.Create(); err != nil {
log.Error("err while creating the koding channel:", err.Error())
return
}
}
socialApiAnnouncementChannelId := strconv.FormatInt(c.Id, 10)
if group.SocialApiAnnouncementChannelId == socialApiAnnouncementChannelId {
log.Info("mongo and postgres socialApiAnnouncementChannel ids are same")
return
}
log.Debug("mongo and postgres socialApiAnnouncementChannel ids are different, fixing it")
if err := updateGroupPartially(group.Id, "socialApiAnnouncementChannelId", strconv.FormatInt(c.Id, 10)); err != nil {
log.Error("err while udpating socialApiAnnouncementChannelId:", err.Error())
return
}
}
示例11: 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
}
示例12: startIntervalerIfNeeded
// startIntervalerIfNeeded starts the given rsync interval, logs any errors, and adds the
// resulting Intervaler to the Mount struct for later Stoppage.
func startIntervalerIfNeeded(log logging.Logger, remoteMachine *machine.Machine, c *rsync.Client, opts rsync.SyncIntervalOpts) {
log = log.New("startIntervalerIfNeeded")
if opts.Interval <= 0 {
// Using debug, because this is not an error - just informative.
log.Debug(
"startIntervalerIfNeeded() called with interval:%d. Cannot start Intervaler",
opts.Interval,
)
return
}
log.Info("Creating and starting RSync SyncInterval")
intervaler, err := c.SyncInterval(opts)
if err != nil {
log.Error("rsync SyncInterval returned an error:%s", err)
return
}
remoteMachine.Intervaler = intervaler
}
示例13: StopCommand
// StopCommand stop local klient. Requires sudo.
func StopCommand(c *cli.Context, log logging.Logger, _ string) int {
if len(c.Args()) != 0 {
cli.ShowCommandHelp(c, "stop")
return 1
}
s, err := newService(nil)
if err != nil {
log.Error("Error creating Service. err:%s", err)
fmt.Println(GenericInternalError)
return 1
}
if err := s.Stop(); err != nil {
log.Error("Error stopping Service. err:%s", err)
fmt.Println(FailedStopKlient)
return 1
}
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
}
fmt.Printf("Successfully stopped %s\n", config.KlientName)
return 0
}
示例14: FactoryAction
// FactoryAction implements a cli.Command's Action field.
func FactoryAction(factory CommandFactory, log logging.Logger, cmdName string) cli.ActionFunc {
return func(c *cli.Context) error {
cmd := factory(c, log, cmdName)
exit, err := cmd.Run()
// For API reasons, we may return an error but a zero exit code. So we want
// to check and log both.
if exit != 0 || err != nil {
log.Error(
"Command encountered error. command:%s, exit:%d, err:%s",
cmdName, exit, err,
)
// Print error message to the user.
fmt.Fprintf(os.Stderr, "error executing %q command: %s\n", cmdName, err)
}
Close()
ExitFunc(exit)
return nil
}
}
示例15: startKlient
func startKlient(log logging.Logger, s service.Service) error {
// For debug purposes, run a health check before we even attempt to start. This
// will help give us a sense of what this machine's health check was before
// klient tried to start.
if res, ok := defaultHealthChecker.CheckAllExceptRunning(); !ok {
log.Warning("before attempting to start klient health check returned not-okay. reason: %s", res)
}
if err := s.Start(); err != nil {
log.Error("Error starting Service. err:%s", err)
fmt.Println(FailedStartKlient)
return err
}
fmt.Println("Starting...")
err := WaitUntilStarted(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",
CommandAttempts, err,
)
if s, ok := defaultHealthChecker.CheckAllExceptRunning(); !ok {
fmt.Printf(`Failed to start %s in time.
A health check found the following issue:
%s
`, config.KlientName, s)
} else {
fmt.Println(FailedStartKlient)
}
return err
}
return nil
}