示例#1
0
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
}
示例#2
0
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
}
示例#3
0
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!")
}
示例#4
0
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")
}
示例#5
0
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
}
示例#6
0
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
	}
}
示例#7
0
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
}
示例#8
0
文件: log.go 项目: unirita/gocutoweb
// Trace outputs trace level message.
func Trace(msg ...interface{}) {
	if !isValid {
		return
	}
	mutex.Lock()
	defer mutex.Unlock()
	seelog.Trace(msg...)
}
示例#9
0
文件: log.go 项目: unikk/cuto
// traceレベルでログメッセージを出力する。
//
// param : msg 出力するメッセージ。複数指定した場合は結合して出力される。
func Trace(msg ...interface{}) {
	if !valid {
		return
	}
	locker.Lock(lockTimeout)
	defer locker.Unlock()
	seelog.Trace(msg...)
}
示例#10
0
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
}
示例#11
0
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
}
示例#12
0
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
}
示例#13
0
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)
}
示例#14
0
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!")
}
示例#15
0
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
}
示例#16
0
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!")
}
示例#18
0
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)
	}
}
示例#19
0
文件: worker.go 项目: espang/examples
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()
	}
}
示例#20
0
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")
}
示例#21
0
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")
}
示例#22
0
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")
}
示例#23
0
文件: discovery.go 项目: armada-io/h2
// 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
}
示例#24
0
文件: main.go 项目: espang/examples
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)
	}
}
示例#25
0
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!")
}
示例#26
0
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!")
}
示例#27
0
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!")
}
示例#28
0
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!")
}
示例#29
0
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!")
}