예제 #1
0
func TestMessageWrite(t *testing.T) {
	m := NewMessage(r.NewRecord())
	m.Level(l.DEBUG).Write("|%s", "4CDA289F-4659-4CE7-825E-5BD766F8C808").Prepare()
	if m.Record.Message != "|4CDA289F-4659-4CE7-825E-5BD766F8C808" {
		t.Errorf("Error in Write()")
	}
}
예제 #2
0
func TestDestructor(t *testing.T) {
	var m = NewMessage(r.NewRecord())
	destructor(m)
	if m.Record != nil {
		t.Errorf("Error in destructor()")
	}
}
예제 #3
0
func TestNewMessage(t *testing.T) {
	var rc *r.Record = r.NewRecord()
	var m *Message = NewMessage(rc)
	if m == nil {
		t.Errorf("Error in NewMessage()")
	}
}
예제 #4
0
func TestMessageLevel(t *testing.T) {
	m := NewMessage(r.NewRecord())
	m.Level(l.DEBUG)
	if m.level != l.DEBUG || m.Record.Level != l.DEBUG {
		t.Errorf("Error in Level()")
	}
	m.Level(l.CRITICAL)
	if m.level != l.CRITICAL || m.Record.Level != l.CRITICAL {
		t.Errorf("Error in Level()")
	}
}
예제 #5
0
파일: trace.go 프로젝트: webdeskltd/log
func (this *Trace) Trace(level int) *Trace {
	var ok bool
	var pc uintptr
	var fn *runtime.Func
	var buf []byte
	var tmp []string
	var i int

	this.Record = r.NewRecord()
	if level == 0 {
		level = STEP_BACK
	}
	buf = make([]byte, 1<<16)
	pc, this.Record.FileNameLong, this.Record.FileLine, ok = runtime.Caller(level)
	if ok == true {
		fn = runtime.FuncForPC(pc)
		if fn != nil {
			this.Record.Function = fn.Name()
		}
		i = runtime.Stack(buf, true)
		this.Record.CallStack = string(buf[:i])

		tmp = strings.Split(this.Record.Function, packageSeparator)
		if len(tmp) > 1 {
			this.Record.Package += strings.Join(tmp[:len(tmp)-1], packageSeparator)
			this.Record.Function = tmp[len(tmp)-1]
		}
		tmp = strings.SplitN(this.Record.Function, `.`, 2)
		if len(tmp) == 2 {
			if this.Record.Package != "" {
				this.Record.Package += packageSeparator
			}
			this.Record.Package += tmp[0]
			this.Record.Function = tmp[1]
		}

		// Filename short
		tmp = strings.Split(this.Record.FileNameLong, packageSeparator)
		if len(tmp) > 0 {
			this.Record.FileNameShort = tmp[len(tmp)-1]
		}

		// Module name
		tmp = strings.Split(this.Record.Package, packageSeparator)
		if len(tmp) > 0 {
			this.Record.Module = tmp[len(tmp)-1]
		}
	}
	return this
}
예제 #6
0
func TestMessageSetResult(t *testing.T) {
	var i int
	var err, resp error

	err = errors.New("Test error")
	m := NewMessage(r.NewRecord())
	go func() {
		t.Logf("Sleep one second")
		time.Sleep(time.Second)
		m.SetResult(101, err)
		t.Logf("Sleep done.")
	}()

	i, resp = m.GetResult()
	if i != 101 || resp != err {
		t.Errorf("Error in SetResult() if GetResult()")
	}

}