本文整理匯總了Golang中github.com/funkygao/log4go.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: doRotate
func (this *AccessLogger) doRotate() {
var fname string
_, err := os.Lstat(this.filename)
if err == nil {
// file exists, find a empty slot
num := 1
for ; err == nil && num <= 999; num++ {
fname = this.filename + fmt.Sprintf(".%03d", num)
_, err = os.Lstat(fname)
}
if err == nil {
log.Error("Access logger unable to rotate, 30 years passed?")
return
}
}
this.fd.Close()
this.fd = nil
// if fd does not close, after rename, fd.Write happens
// content will be written to new file
err = os.Rename(this.filename, fname)
if err != nil {
log.Error("rename %s->%s: %v", this.filename, fname)
return
}
if this.fd, err = os.OpenFile(this.filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660); err != nil {
log.Error("open(%s): %s", this.filename, err)
}
}
示例2: Start
func (this *mysqlStore) Start() error {
if err := this.refreshFromMysql(); err != nil {
// refuse to start if mysql conn fails
return fmt.Errorf("manager[%s]: %v", this.Name(), err)
}
go func() {
ticker := time.NewTicker(this.cf.Refresh)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if err := this.refreshFromMysql(); err != nil {
log.Error(err.Error())
} else {
log.Info("manager refreshed from mysql")
}
case <-this.refreshCh:
if err := this.refreshFromMysql(); err != nil {
log.Error(err.Error())
} else {
log.Info("manager forced to refresh from mysql")
}
case <-this.shutdownCh:
log.Info("mysql manager stopped")
return
}
}
}()
return nil
}
示例3: Warmup
func (this *Client) Warmup() {
var (
sess *mgo.Session
err error
t1 = time.Now()
)
for retries := 0; retries < 3; retries++ {
for _, server := range this.selector.ServerList() {
sess, err = this.getConn(server.Uri())
if err != nil {
log.Error("Warmup %v fail: %s", server.Uri(), err)
break
} else {
this.putFreeConn(server.Uri(), sess)
}
}
if err == nil {
break
}
}
if err == nil {
log.Trace("Mongodb warmup within %s: %+v",
time.Since(t1), this.freeconns)
} else {
log.Error("Mongodb failed to warmup within %s: %s",
time.Since(t1), err)
}
}
示例4: diagnose
func (this *Ping) diagnose() {
this.zkzone.ForSortedClusters(func(zkcluster *zk.ZkCluster) {
registeredBrokers := zkcluster.RegisteredInfo().Roster
for _, broker := range registeredBrokers {
log.Debug("ping %s", broker.Addr())
kfk, err := sarama.NewClient([]string{broker.Addr()}, sarama.NewConfig())
if err != nil {
log.Error("%25s %30s %s", broker.Addr(), broker.NamedAddr(), color.Red(err.Error()))
continue
}
_, err = kfk.Topics() // kafka didn't provide ping, so use Topics() as ping
if err != nil {
log.Error("%25s %30s %s", broker.Addr(), broker.NamedAddr(), color.Red(err.Error()))
} else {
if !this.problematicMode {
log.Info("%25s %30s %s", broker.Addr(), broker.NamedAddr(), color.Green("ok"))
}
}
kfk.Close()
}
})
}
示例5: housekeeping
func (q *queue) housekeeping() {
defer func() {
log.Trace("queue[%s] housekeeping done", q.ident())
q.wg.Done()
}()
log.Trace("queue[%s] start housekeeping...", q.ident())
purgeTick := time.NewTicker(q.purgeInterval)
defer purgeTick.Stop()
cursorChkpnt := time.NewTicker(time.Second)
defer cursorChkpnt.Stop()
for {
select {
case <-purgeTick.C:
if err := q.Purge(); err != nil {
log.Error("queue[%s] purge: %s", q.ident(), err)
}
case <-cursorChkpnt.C:
if err := q.cursor.dump(); err != nil {
log.Error("queue[%s] cursor checkpoint: %s", q.ident(), err)
}
case <-q.quit:
return
}
}
}
示例6: InfluxDB
// InfluxDB starts a InfluxDB reporter which will post the metrics from the given registry at each d interval.
// CREATE RETENTION POLICY two_hours ON food_data DURATION 2h REPLICATION 1 DEFAULT
// SHOW RETENTION POLICIES ON food_data
// CREATE CONTINUOUS QUERY cq_30m ON food_data BEGIN SELECT mean(website) AS mean_website,mean(phone) AS mean_phone INTO food_data."default".downsampled_orders FROM orders GROUP BY time(30m) END
func InfluxDB(hostname string, r metrics.Registry, interval time.Duration,
url, database, username, password string, stop chan struct{}) {
u, err := uurl.Parse(url)
if err != nil {
log.Error("unable to parse InfluxDB url %s. err=%v", url, err)
return
}
rep := &reporter{
reg: r,
interval: interval,
stop: stop,
url: *u,
database: database,
hostname: hostname,
username: username,
password: password,
}
if err := rep.makeClient(); err != nil {
log.Error("unable to make InfluxDB client. err=%v", err)
return
}
rep.run()
}
示例7: reloadHAproxy
func (this *Start) reloadHAproxy() (err error) {
var cmd *exec.Cmd = nil
waitStartCh := make(chan struct{})
if this.starting {
log.Info("haproxy starting")
cmd = exec.Command(this.command, "-f", configFile) // TODO use absolute path
this.starting = false
go func() {
<-waitStartCh
log.Info("haproxy started")
if err := cmd.Wait(); err != nil {
log.Error("haproxy: %v", err)
}
}()
} else {
shellScript := fmt.Sprintf("%s -f %s/%s -sf `cat %s/%s`",
this.command, this.root, configFile, this.root, haproxyPidFile)
log.Info("haproxy reloading: %s", shellScript)
cmd = exec.Command("/bin/sh", "-c", shellScript)
go func() {
<-waitStartCh
log.Info("haproxy reloaded")
if err := cmd.Wait(); err != nil {
log.Error("haproxy: %v", err)
}
}()
}
if err = cmd.Start(); err == nil {
waitStartCh <- struct{}{}
}
return err
}
示例8: loadTemplates
func loadTemplates() {
if config.faeTemplateFile != "" {
body, err := ioutil.ReadFile(config.faeTemplateFile)
if err != nil {
log.Error("template[%s]: %s", config.faeTemplateFile, err)
} else {
faeTemplateContents = string(body)
log.Info("template[%s] loaded", config.faeTemplateFile)
}
}
if config.actorTemplateFile != "" {
body, err := ioutil.ReadFile(config.actorTemplateFile)
if err != nil {
log.Error("template[%s]: %s", config.actorTemplateFile, err)
} else {
maintainTemplateContents = string(body)
log.Info("template[%s] loaded", config.actorTemplateFile)
}
}
if config.maintainTemplateFile != "" {
body, err := ioutil.ReadFile(config.maintainTemplateFile)
if err != nil {
log.Error("template[%s]: %s", config.maintainTemplateFile, err)
} else {
maintainTemplateContents = string(body)
log.Info("template[%s] loaded", config.maintainTemplateFile)
}
}
}
示例9: Attr
func (f *File) Attr(ctx context.Context, o *fuse.Attr) error {
f.RLock()
defer f.RUnlock()
*o = f.attr
// calculate size
if !f.opened {
if err := f.dir.reconnectKafkaIfNecessary(); err != nil {
return err
}
latestOffset, err := f.dir.GetOffset(f.topic, f.partitionId, sarama.OffsetNewest)
if err != nil {
log.Error(err)
return err
}
oldestOffset, err := f.dir.GetOffset(f.topic, f.partitionId, sarama.OffsetOldest)
if err != nil {
log.Error(err)
return err
}
o.Size = uint64(latestOffset - oldestOffset)
} else {
o.Size = uint64(len(f.content))
}
log.Trace("File Attr, topic=%s, partitionId=%d, size=%d", f.topic, f.partitionId, o.Size)
return nil
}
示例10: shutdown
func (this *Start) shutdown() {
// kill haproxy
log.Info("killling haproxy processes")
f, e := os.Open(haproxyPidFile)
if e != nil {
log.Error("shutdown %v", e)
return
}
reader := bufio.NewReader(f)
for {
l, e := gio.ReadLine(reader)
if e != nil {
// EOF
break
}
pid, _ := strconv.Atoi(string(l))
p := &os.Process{
Pid: pid,
}
if err := p.Kill(); err != nil {
log.Error(err)
} else {
log.Info("haproxy[%d] terminated", pid)
}
}
log.Info("removing %s", haproxyPidFile)
os.Remove(haproxyPidFile)
}
示例11: updateRedisSlowlog
func (this *WatchSlowlog) updateRedisSlowlog(wg *sync.WaitGroup, host string, port int, tag string) {
defer wg.Done()
spec := redis.DefaultSpec().Host(host).Port(port)
client, err := redis.NewSynchClientWithSpec(spec)
if err != nil {
log.Error("redis[%s:%d]: %v", host, port, err)
return
}
defer client.Quit()
n, err := client.SlowlogLen()
if err != nil {
log.Error("redis[%s:%d]: %v", host, port, err)
return
}
if n == 0 {
return
}
this.mu.Lock()
this.slows[tag] = metrics.NewRegisteredGauge(tag+"redis.slowlog", nil)
this.slows[tag].Update(n)
this.mu.Unlock()
}
示例12: updateMetrics
func (this *haproxyMetrics) updateMetrics(records map[string]map[string]int64) (err error) {
for svcName, svcCols := range records {
//find svc
svcMetrics, present := this.svcMetricsMap[svcName]
if !present {
log.Error("svcName[%s] not in svcMetricsMap[%#v]", svcName, this.svcMetricsMap)
err = ErrUnsupService
return err
}
//update col value
for colName, colVal := range svcCols {
//find gague
gauge, present := svcMetrics.metricsMap[colName]
if !present {
log.Error("colName[%s] not in metricsMap[%#v]", colName, svcMetrics.metricsMap)
err = ErrMetricsNotFound
return err
}
//update gauge
gauge.Update(colVal)
}
}
return
}
示例13: CallSOS
// CallSOS will send SOS message to the zone wide kguard leader.
func (this *ZkZone) CallSOS(caller string, msg string) {
log.Critical("SOS[%s] %s: sending...", caller, msg)
// kguard leader might float, so refresh on each SOS message
kguards, err := this.KguardInfos()
if err != nil {
log.Error("SOS[%s] %s: %v", caller, msg, err)
return
}
leader := kguards[0]
request := gorequest.New().Timeout(time.Second * 10)
res, body, errs := request.Post(fmt.Sprintf("http://%s:%d", leader.Host, telemetry.SOSPort)).
Set("User-Agent", fmt.Sprintf("sos-go-%s", gafka.BuildId)).
Set(telemetry.SOSIdentHeader, caller).
End()
if len(errs) > 0 {
log.Error("SOS[%s] %s: %+v", caller, msg, errs)
return
}
if res.StatusCode != http.StatusAccepted {
log.Error("SOS[%s] %s: HTTP %s %s", caller, msg, http.StatusText(res.StatusCode), body)
return
}
log.Info("SOS[%s] %s: sent ok", caller, msg)
}
示例14: createJobHandler
// @rest POST /v1/jobs/:appid/:topic/:ver
func (this *manServer) createJobHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
topic := params.ByName(UrlParamTopic)
if !manager.Default.ValidateTopicName(topic) {
log.Warn("illegal topic: %s", topic)
writeBadRequest(w, "illegal topic")
return
}
realIp := getHttpRemoteIp(r)
if !this.throttleAddTopic.Pour(realIp, 1) {
writeQuotaExceeded(w)
return
}
hisAppid := params.ByName(UrlParamAppid)
appid := r.Header.Get(HttpHeaderAppid)
pubkey := r.Header.Get(HttpHeaderPubkey)
ver := params.ByName(UrlParamVersion)
if !manager.Default.AuthAdmin(appid, pubkey) {
log.Warn("suspicous create job %s(%s) {appid:%s pubkey:%s topic:%s ver:%s}",
r.RemoteAddr, realIp, appid, pubkey, topic, ver)
writeAuthFailure(w, manager.ErrAuthenticationFail)
return
}
cluster, found := manager.Default.LookupCluster(hisAppid)
if !found {
log.Error("create job %s(%s) {appid:%s topic:%s ver:%s} invalid appid",
r.RemoteAddr, realIp, hisAppid, topic, ver)
writeBadRequest(w, "invalid appid")
return
}
log.Info("create job[%s] %s(%s) {appid:%s topic:%s ver:%s}",
appid, r.RemoteAddr, realIp, hisAppid, topic, ver)
rawTopic := manager.Default.KafkaTopic(hisAppid, topic, ver)
if err := job.Default.CreateJobQueue(Options.AssignJobShardId, hisAppid, rawTopic); err != nil {
log.Error("create job[%s] %s(%s) {shard:%d appid:%s topic:%s ver:%s} %v",
appid, r.RemoteAddr, realIp, Options.AssignJobShardId, hisAppid, topic, ver, err)
writeServerError(w, err.Error())
return
}
if err := this.gw.zkzone.CreateJobQueue(rawTopic, cluster); err != nil {
log.Error("app[%s] %s(%s) create job: {shard:%d appid:%s topic:%s ver:%s} %v",
appid, r.RemoteAddr, realIp, Options.AssignJobShardId, hisAppid, topic, ver, err)
writeServerError(w, err.Error())
return
}
w.WriteHeader(http.StatusCreated)
w.Write(ResponseOk)
}
示例15: run
func (r *reporter) run() {
intervalTicker := time.Tick(r.interval)
//pingTicker := time.Tick(time.Second * 5)
pingTicker := time.Tick(r.interval / 2)
for {
select {
// TODO on shutdown, flush all metrics
case <-r.stop:
return
case <-intervalTicker:
if err := r.send(); err != nil {
log.Error("unable to send metrics to InfluxDB. err=%v", err)
}
case <-pingTicker:
_, _, err := r.client.Ping()
if err != nil {
log.Error("got error while sending a ping to InfluxDB, trying to recreate client. err=%v", err)
if err = r.makeClient(); err != nil {
log.Error("unable to make InfluxDB client. err=%v", err)
}
}
}
}
}