Beispiel #1
0
func (lm *_LogManage) logItem(level log.LogLevel, tag log.LogTag, msg string) log.LogItem {
	item := log.LogItem{
		ID:      atomic.AddUint64(&lm.gID, 1),
		Level:   level,
		Time:    time.Now(),
		Tag:     tag,
		Message: msg,
	}
	if lm.Config.Global.ShowFile == 1 {
		item.File = lm.file()
	}
	return item
}
Beispiel #2
0
func TestMemoryPush(t *testing.T) {
	memBuf := NewMemoryBuffer()
	var item log.LogItem
	item.ID = 1
	item.Time = time.Now()
	item.Tag = log.DefaultTag
	item.Level = log.DEBUG
	item.Message = "Test message..."
	memBuf.Push(item)
	lItem, _ := memBuf.Pop()
	t.Log(lItem)
	lItem, _ = memBuf.Front()
	t.Log(lItem)
}
Beispiel #3
0
func TestRedisPush(t *testing.T) {
	config := log.RedisConfig{
		Addr: "192.168.33.70:6379",
		DB:   1,
	}
	redisBuf := NewRedisBuffer(config)
	var item log.LogItem
	item.ID = 1
	item.Time = time.Now()
	item.Tag = log.DefaultTag
	item.Level = log.DEBUG
	item.Message = "Test redis message..."
	err := redisBuf.Push(item)
	if err != nil {
		t.Error(err)
		return
	}
	t.Log("Success")
}
Beispiel #4
0
func TestMongoStore(t *testing.T) {
	var cfg log.MongoConfig
	cfg.URL = "mongodb://192.168.33.70:27017"
	store := NewMongoStore(cfg)
	var err error
	for i := 0; i < 1000; i++ {
		var item log.LogItem
		item.ID = uint64(i)
		item.Time = time.Now()
		item.Level = log.INFO
		item.Tag = log.DefaultTag
		item.Message = ".........................."
		err = store.Store(&item)
		if err != nil {
			break
		}
	}
	if err != nil {
		t.Error(err)
		return
	}
	t.Log("Write success.")
}
Beispiel #5
0
func (ms *MongoStore) Store(item *log.LogItem) error {
	dbName := log.ParseName(ms.dbTmpl, item)
	collectionName := log.ParseName(ms.collectionTmpl, item)
	err := ms.session.DB(dbName).C(collectionName).Insert(item.ToMap())
	return err
}