-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_test.go
More file actions
35 lines (30 loc) · 886 Bytes
/
log_test.go
File metadata and controls
35 lines (30 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package golog
import (
"context"
"testing"
"time"
)
func TestFileCreateAndDelete(t *testing.T) {
logger := Default()
logger.maxKeepDays = 3
logger.date = int32(time.Now().YearDay() - 1)
createDateFolder(logger.rootPath, "2024-05-12")
createDateFolder(logger.rootPath, "2024-05-11")
createDateFolder(logger.rootPath, "2024-05-10")
createDateFolder(logger.rootPath, "2024-05-09")
logger.Debug(context.Background(), "test logger")
logger.Debug(context.Background(), "test logger")
logger.Debug(context.Background(), "test logger")
}
func TestLogTrack(t *testing.T) {
logger := Default()
ctx := context.Background()
ctx = context.WithValue(ctx, "traceKey", map[string]any{
"request_id": 123,
"user_id": "456",
})
logger.Debug(ctx, "log for debug")
logger.Info(ctx, "log for info")
logger.Warning(ctx, "log for warning")
logger.Error(ctx, "log for error")
}