func (fr *TrecFileReader) ReadAll() <-chan Document { defer func() { if x := recover(); x != nil { log.Flush() } }() log.Trace("Reading documents") fr.scanner.Reset() log.Trace("Reset") go fr.read_to_chan(-1) return fr.documents }
func (s *ESAPIV0) NextScroll(scrollTime string, scrollId string) (*Scroll, error) { // curl -XGET 'http://es-0.9:9200/_search/scroll?scroll=5m' id := bytes.NewBufferString(scrollId) url := fmt.Sprintf("%s/_search/scroll?scroll=%s&scroll_id=%s", s.Host, scrollTime, id) resp, body, errs := Get(url, s.Auth, s.HttpProxy) if errs != nil { log.Error(errs) return nil, errs[0] } if resp.StatusCode != 200 { return nil, errors.New(body) } defer resp.Body.Close() log.Trace("next scroll,", url, body) // decode elasticsearch scroll response scroll := &Scroll{} err := json.Unmarshal([]byte(body), &scroll) if err != nil { log.Error(body) log.Error(err) return nil, err } return scroll, nil }
func dateTimeFormat() { fmt.Println("Date time format") testConfig := ` <seelog type="sync"> <outputs formatid="main"> <console/> </outputs> <formats> <format id="main" format="%Date/%Time [%LEV] %Msg%n"/> </formats> </seelog>` logger, err := log.LoggerFromConfigAsBytes([]byte(testConfig)) if err != nil { fmt.Println(err) } loggerErr := log.ReplaceLogger(logger) if loggerErr != nil { fmt.Println(loggerErr) } log.Trace("Test message!") }
func testFuncException() { fmt.Println("testFuncException") testConfig := ` <seelog type="sync" minlevel="info"> <exceptions> <exception funcpattern="*main.test*Except*" minlevel="error"/> </exceptions> <outputs> <console/> </outputs> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("NOT Printed") log.Debug("NOT Printed") log.Info("NOT Printed") log.Warn("NOT Printed") log.Error("Printed") log.Critical("Printed") log.Current.Trace("NOT Printed") log.Current.Debug("NOT Printed") log.Current.Info("NOT Printed") log.Current.Warn("NOT Printed") log.Current.Error("Printed") log.Current.Critical("Printed") }
func (c *memcacheCacher) doFetch(sessId string) (u *User, cacheHit bool, err error) { it, err := mc.Get(sessId) if err != nil && err != memcache.ErrCacheMiss { // actual error log.Warnf("[Auth] Token cache fetch error for '%s': %v", sessId, err) return nil, false, err } if err == memcache.ErrCacheMiss { // not found - not an error though log.Trace("[Auth] Token cache - miss") return nil, false, nil } if bytes.Equal(it.Value, []byte(invalidPlaceholder)) { // cached invalid log.Tracef("[Auth] Token cache - invalid placeholder in cache for %s", sessId) return nil, true, nil } u, err = FromSessionToken(sessId, string(it.Value)) if err != nil { // found, but we can't decode - treat as not found log.Warnf("[Auth] Token cache decode error: %v", err) return nil, false, nil } return u, true, nil }
func (s *ESAPIV0) Bulk(data *bytes.Buffer) { if data == nil || data.Len() == 0 { return } data.WriteRune('\n') url := fmt.Sprintf("%s/_bulk", s.Host) client := &http.Client{} reqest, _ := http.NewRequest("POST", url, data) if s.Auth != nil { reqest.SetBasicAuth(s.Auth.User, s.Auth.Pass) } resp, errs := client.Do(reqest) if errs != nil { log.Error(errs) return } body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Error(err) return } log.Trace(url, string(body)) defer resp.Body.Close() defer data.Reset() if resp.StatusCode != 200 { log.Errorf("bad bulk response: %s %s", body, resp.StatusCode) return } }
func (ss *Session) RawMessage(msg []byte) error { log.Trace("RawMessage ", string(msg)) packet, err := decodePacket(msg) if err != nil { log.Info("decodePacket error ", err, string(msg)) return nil } if packet == nil { log.Info("packet == nil ") return nil } if packet.EndPoint() == "" { if err := ss.onPacket(packet); err != nil { log.Error(err) return nil } } ns := ss.Of(packet.EndPoint()) if ns == nil { return nil } ns.onPacket(packet) return nil }
// Trace outputs trace level message. func Trace(msg ...interface{}) { if !isValid { return } mutex.Lock() defer mutex.Unlock() seelog.Trace(msg...) }
// traceレベルでログメッセージを出力する。 // // param : msg 出力するメッセージ。複数指定した場合は結合して出力される。 func Trace(msg ...interface{}) { if !valid { return } locker.Lock(lockTimeout) defer locker.Unlock() seelog.Trace(msg...) }
func (this *Receiver) OnRegResp(arg ArgOnRegResp, reply *ReplyOnRegResp) error { log.Trace("RPC: OnRegResp") log.Infof("Regist response: RegId: %s, Result: %d", arg.RegId, arg.Result) this.RegId = arg.RegId if arg.Result != 0 { log.Error("Regist failed") } return nil }
func (s *ESAPIV5) NewScroll(indexNames string, scrollTime string, docBufferCount int, query string, slicedId, maxSlicedCount int) (scroll *Scroll, err error) { url := fmt.Sprintf("%s/%s/_search?scroll=%s&size=%d", s.Host, indexNames, scrollTime, docBufferCount) jsonBody := "" if len(query) > 0 || maxSlicedCount > 0 { queryBody := map[string]interface{}{} if len(query) > 0 { queryBody["query"] = map[string]interface{}{} queryBody["query"].(map[string]interface{})["query_string"] = map[string]interface{}{} queryBody["query"].(map[string]interface{})["query_string"].(map[string]interface{})["query"] = query } if maxSlicedCount > 1 { log.Tracef("sliced scroll, %d of %d", slicedId, maxSlicedCount) queryBody["slice"] = map[string]interface{}{} queryBody["slice"].(map[string]interface{})["id"] = slicedId queryBody["slice"].(map[string]interface{})["max"] = maxSlicedCount } jsonArray, err := json.Marshal(queryBody) if err != nil { log.Error(err) } else { jsonBody = string(jsonArray) } } resp, body, errs := Post(url, s.Auth, jsonBody, s.HttpProxy) if errs != nil { log.Error(errs) return nil, errs[0] } defer resp.Body.Close() if resp.StatusCode != 200 { return nil, errors.New(body) } log.Trace("new scroll,", body) if err != nil { log.Error(err) return nil, err } scroll = &Scroll{} err = json.Unmarshal([]byte(body), scroll) if err != nil { log.Error(err) return nil, err } return scroll, err }
func (this *Receiver) OnReceiveMsg(arg ArgOnReceiveMsg, reply *ReplyOnReceiveMsg) error { log.Trace("RPC: OnReceiveMsg") log.Infof("Received message. MsgId: %d, MsgType: %d, Msg: %s", arg.MsgId, arg.MsgType, arg.Msg) if lastMsgId == 0 { lastMsgId = arg.MsgId } else if lastMsgId >= arg.MsgId { log.Errorf("Received bad message Id: %d, LastMsgId: %d", arg.MsgId, lastMsgId) } return nil }
func doTest() { start := time.Now() for i := 0; i < 50; i += 2 { fmt.Printf("%d\n", i) log.Trace(longMessage) log.Debugf("%d", i+1) } end := time.Now() dur := end.Sub(start) fmt.Printf("Test took %d ns\n", dur) }
func defaultFormat() { fmt.Println("Default format") testConfig := ` <seelog type="sync" />` logger, err := log.LoggerFromConfigAsBytes([]byte(testConfig)) if err != nil { fmt.Println(err) } log.ReplaceLogger(logger) log.Trace("Test message!") }
func Request(method string, r string, auth *Auth, body *bytes.Buffer, proxy string) (string, error) { var client *http.Client client = &http.Client{} if len(proxy) > 0 { proxyURL, err := url.Parse(proxy) if err != nil { log.Error(err) } else { transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)} client = &http.Client{Transport: transport} } } var reqest *http.Request if body != nil { reqest, _ = http.NewRequest(method, r, body) } else { reqest, _ = newDeleteRequest(client, method, r) } if auth != nil { reqest.SetBasicAuth(auth.User, auth.Pass) } resp, errs := client.Do(reqest) if errs != nil { log.Error(errs) return "", errs } if resp.StatusCode != 200 { b, _ := ioutil.ReadAll(resp.Body) return "", errors.New("server error: " + string(b)) } respBody, err := ioutil.ReadAll(resp.Body) if err != nil { log.Error(err) return string(respBody), err } log.Trace(r, string(respBody)) if err != nil { return string(respBody), err } defer resp.Body.Close() return string(respBody), nil }
func (s *ESAPIV0) NewScroll(indexNames string, scrollTime string, docBufferCount int, query string, slicedId, maxSlicedCount int) (scroll *Scroll, err error) { // curl -XGET 'http://es-0.9:9200/_search?search_type=scan&scroll=10m&size=50' url := fmt.Sprintf("%s/%s/_search?search_type=scan&scroll=%s&size=%d", s.Host, indexNames, scrollTime, docBufferCount) jsonBody := "" if len(query) > 0 { queryBody := map[string]interface{}{} queryBody["query"] = map[string]interface{}{} queryBody["query"].(map[string]interface{})["query_string"] = map[string]interface{}{} queryBody["query"].(map[string]interface{})["query_string"].(map[string]interface{})["query"] = query jsonArray, err := json.Marshal(queryBody) if err != nil { log.Error(err) } else { jsonBody = string(jsonArray) } } resp, body, errs := Post(url, s.Auth, jsonBody, s.HttpProxy) if err != nil { log.Error(errs) return nil, errs[0] } defer resp.Body.Close() log.Trace("new scroll,", url, body) if err != nil { log.Error(err) return nil, err } if resp.StatusCode != 200 { return nil, errors.New(body) } scroll = &Scroll{} err = json.Unmarshal([]byte(body), scroll) if err != nil { log.Error(err) return nil, err } return scroll, err }
func levelsFormatter() { testConfig := ` <seelog type="sync"> <outputs formatid="main"> <console/> </outputs> <formats> <format id="main" format="%MyLevel %Msg%n"/> </formats> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Test message!") }
func (r *Result) log() { json, err := jsonutil.Encode(r) if err != nil { log.Error(err) } if r.Failed { log.Error(json) } else if r.Changed { log.Info(json) } else if !r.Skipped { log.Debug(json) } else { log.Trace(json) } }
func main() { defer seelog.Flush() seelog.Trace("Start nats worker") s = &Stats{TotalTime: time.Duration(0), WorkCount: 0} nc, err := nats.Connect(nats.DefaultURL) if err != nil { seelog.Errorf("Connecting: %s", err) os.Exit(1) } nc.Opts.AllowReconnect = false // Report async errors. nc.Opts.AsyncErrorCB = func(nc *nats.Conn, sub *nats.Subscription, err error) { seelog.Errorf("NATS: Received an async error! %v\n", err) os.Exit(1) } // Report a disconnect scenario. nc.Opts.DisconnectedCB = func(nc *nats.Conn) { seelog.Errorf("Getting behind! %d\n", nc.OutMsgs-nc.InMsgs) os.Exit(1) } ec, err := nats.NewEncodedConn(nc, nats.GOB_ENCODER) if err != nil { seelog.Errorf("Encoded connection: %s", err) os.Exit(1) } recvChannel := make(chan *Work, 20) ec.BindRecvQueueChan("Work", "job_workers", recvChannel) doneChannel := make(chan *Work, 20) ec.BindSendChan("Done", doneChannel) go worker(recvChannel, doneChannel) go worker(recvChannel, doneChannel) go worker(recvChannel, doneChannel) go worker(recvChannel, doneChannel) tick := time.Tick(time.Minute) for _ = range tick { s.log() } }
func main() { defer log.Flush() log.Info("Hello from Seelog!") consoleWriter, _ := log.NewConsoleWriter() formatter, _ := log.NewFormatter("%Level %Msg %File%n") root, _ := log.NewSplitDispatcher(formatter, []interface{}{consoleWriter}) constraints, _ := log.NewMinMaxConstraints(log.TraceLvl, log.CriticalLvl) specificConstraints, _ := log.NewListConstraints([]log.LogLevel{log.InfoLvl, log.ErrorLvl}) ex, _ := log.NewLogLevelException("*", "*main.go", specificConstraints) exceptions := []*log.LogLevelException{ex} logger := log.NewAsyncLoopLogger(log.NewLoggerConfig(constraints, exceptions, root)) log.ReplaceLogger(logger) log.Trace("This should not be seen") log.Debug("This should not be seen") log.Info("Test") log.Error("Test2") }
func testMinMax() { fmt.Println("testMinMax") testConfig := ` <seelog type="sync" minlevel="info" maxlevel="error"> <outputs><console/></outputs> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("NOT Printed") log.Debug("NOT Printed") log.Info("Printed") log.Warn("Printed") log.Error("Printed") log.Critical("NOT Printed") }
func testList() { fmt.Println("testList") testConfig := ` <seelog type="sync" levels="info, trace, critical"> <outputs><console/></outputs> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Printed") log.Debug("NOT Printed") log.Info("Printed") log.Warn("NOT Printed") log.Error("NOT Printed") log.Critical("Printed") }
// connect our service/endpoints to the hive mind // send discovery information on each endpoint to the discovery service // if successful, marks us as connected func (self *discovery) connect() error { log.Trace("[Discovery] Connecting") if err := self.callDiscoveryService("multiregister", true); err != nil { self.isMultiRegistered = false return err } // now connected - set auth scope for service-to-service // @todo ask moddie if this is the place to do this? // I've put it here because i want the login service to work the same way, and it needs to message itself if serviceToServiceAuth { auth.SetCurrentService(Name) } self.isMultiRegistered = true return nil }
func main() { defer seelog.Flush() seelog.Trace("Start nats test program") nc, err := nats.Connect(nats.DefaultURL) if err != nil { seelog.Errorf("connecting: %s", err) os.Exit(1) } c, err := nats.NewEncodedConn(nc, "json") if err != nil { seelog.Errorf("connecting: %s", err) os.Exit(1) } defer c.Close() err = c.Publish("foo", "Hello World") if err != nil { seelog.Errorf("publishing1: %s", err) os.Exit(1) } _, err = c.Subscribe("foo", func(s string) { seelog.Infof("Received a message: %s", s) }) if err != nil { seelog.Errorf("subscribing1: %s", err) os.Exit(1) } _, err = c.Subscribe("hello", func(p *Person) { seelog.Infof("Received a person %#v", p) }) if err != nil { seelog.Errorf("subscribing2: %s", err) os.Exit(1) } person := &Person{Name: "na", Age: 2, Address: "asdf 3773, Germany"} err = c.Publish("hello", person) if err != nil { seelog.Errorf("publishing2: %s", err) os.Exit(1) } }
func dateTimeCustomFormat() { fmt.Println("Date time custom format") testConfig := ` <seelog type="sync"> <outputs formatid="main"> <console/> </outputs> <formats> <format id="main" format="%Date(2006 Jan 02/3:04:05.000000000 PM MST) [%Level] %Msg%n"/> </formats> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Test message!") }
func stdFormat() { fmt.Println("Standard fast format") testConfig := ` <seelog type="sync"> <outputs formatid="main"> <console/> </outputs> <formats> <format id="main" format="%Ns [%Level] %Msg%n"/> </formats> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Test message!") }
func logLevelTypesFormat() { fmt.Println("Log level types format") testConfig := ` <seelog type="sync"> <outputs formatid="main"> <console/> </outputs> <formats> <format id="main" format="%Level %Lev %LEVEL %LEV %l %Msg%n"/> </formats> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Test message!") }
func fileTypesFormat() { fmt.Println("File types format") testConfig := ` <seelog type="sync"> <outputs formatid="main"> <console/> </outputs> <formats> <format id="main" format="%File %FullPath %RelFile %Msg%n"/> </formats> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Test message!") }
func filterDispatcher() { testConfig := ` <seelog> <outputs> <filter levels="trace"> <file path="./log/filter.log"/> </filter> <console /> </outputs> </seelog> ` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) fmt.Println("Filter dispatcher") for i := 0; i < 5; i++ { log.Trace("This message on console and in file") log.Debug("This message only on console") } }
func syslogCustomFormatter() { defer log.Flush() // NOTE: in real usecases a conn writer should be used instead of console. // Example: <conn formatid="syslogfmt" net="tcp4" addr="server.address:5514" tls="true" insecureskipverify="true" /> testConfig := ` <seelog type="sync"> <outputs formatid="syslogfmt"> <console/> </outputs> <formats> <format id="syslogfmt" format="%CustomSyslogHeader(20) %Msg%n"/> </formats> </seelog>` logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) log.ReplaceLogger(logger) log.Trace("Test message!") }