|
1 | 1 | package logx |
2 | 2 |
|
3 | | -// A LogConf is a logging config. |
4 | | -type LogConf struct { |
5 | | - // ServiceName represents the service name. |
6 | | - ServiceName string `json:",optional"` |
7 | | - // Mode represents the logging mode, default is `console`. |
8 | | - // console: log to console. |
9 | | - // file: log to file. |
10 | | - // volume: used in k8s, prepend the hostname to the log file name. |
11 | | - Mode string `json:",default=console,options=[console,file,volume]"` |
12 | | - // Encoding represents the encoding type, default is `json`. |
13 | | - // json: json encoding. |
14 | | - // plain: plain text encoding, typically used in development. |
15 | | - Encoding string `json:",default=json,options=[json,plain]"` |
16 | | - // TimeFormat represents the time format, default is `2006-01-02T15:04:05.000Z07:00`. |
17 | | - TimeFormat string `json:",optional"` |
18 | | - // Path represents the log file path, default is `logs`. |
19 | | - Path string `json:",default=logs"` |
20 | | - // Level represents the log level, default is `info`. |
21 | | - Level string `json:",default=info,options=[debug,info,error,severe]"` |
22 | | - // MaxContentLength represents the max content bytes, default is no limit. |
23 | | - MaxContentLength uint32 `json:",optional"` |
24 | | - // Compress represents whether to compress the log file, default is `false`. |
25 | | - Compress bool `json:",optional"` |
26 | | - // Stat represents whether to log statistics, default is `true`. |
27 | | - Stat bool `json:",default=true"` |
28 | | - // KeepDays represents how many days the log files will be kept. Default to keep all files. |
29 | | - // Only take effect when Mode is `file` or `volume`, both work when Rotation is `daily` or `size`. |
30 | | - KeepDays int `json:",optional"` |
31 | | - // StackCooldownMillis represents the cooldown time for stack logging, default is 100ms. |
32 | | - StackCooldownMillis int `json:",default=100"` |
33 | | - // MaxBackups represents how many backup log files will be kept. 0 means all files will be kept forever. |
34 | | - // Only take effect when RotationRuleType is `size`. |
35 | | - // Even though `MaxBackups` sets 0, log files will still be removed |
36 | | - // if the `KeepDays` limitation is reached. |
37 | | - MaxBackups int `json:",default=0"` |
38 | | - // MaxSize represents how much space the writing log file takes up. 0 means no limit. The unit is `MB`. |
39 | | - // Only take effect when RotationRuleType is `size` |
40 | | - MaxSize int `json:",default=0"` |
41 | | - // Rotation represents the type of log rotation rule. Default is `daily`. |
42 | | - // daily: daily rotation. |
43 | | - // size: size limited rotation. |
44 | | - Rotation string `json:",default=daily,options=[daily,size]"` |
45 | | - // FileTimeFormat represents the time format for file name, default is `2006-01-02T15:04:05.000Z07:00`. |
46 | | - FileTimeFormat string `json:",optional"` |
47 | | - // LogKey represents the log key. |
48 | | - LogKey logKeyConf `json:",optional"` |
49 | | -} |
| 3 | +type ( |
| 4 | + // A LogConf is a logging config. |
| 5 | + LogConf struct { |
| 6 | + // ServiceName represents the service name. |
| 7 | + ServiceName string `json:",optional"` |
| 8 | + // Mode represents the logging mode, default is `console`. |
| 9 | + // console: log to console. |
| 10 | + // file: log to file. |
| 11 | + // volume: used in k8s, prepend the hostname to the log file name. |
| 12 | + Mode string `json:",default=console,options=[console,file,volume]"` |
| 13 | + // Encoding represents the encoding type, default is `json`. |
| 14 | + // json: json encoding. |
| 15 | + // plain: plain text encoding, typically used in development. |
| 16 | + Encoding string `json:",default=json,options=[json,plain]"` |
| 17 | + // TimeFormat represents the time format, default is `2006-01-02T15:04:05.000Z07:00`. |
| 18 | + TimeFormat string `json:",optional"` |
| 19 | + // Path represents the log file path, default is `logs`. |
| 20 | + Path string `json:",default=logs"` |
| 21 | + // Level represents the log level, default is `info`. |
| 22 | + Level string `json:",default=info,options=[debug,info,error,severe]"` |
| 23 | + // MaxContentLength represents the max content bytes, default is no limit. |
| 24 | + MaxContentLength uint32 `json:",optional"` |
| 25 | + // Compress represents whether to compress the log file, default is `false`. |
| 26 | + Compress bool `json:",optional"` |
| 27 | + // Stat represents whether to log statistics, default is `true`. |
| 28 | + Stat bool `json:",default=true"` |
| 29 | + // KeepDays represents how many days the log files will be kept. Default to keep all files. |
| 30 | + // Only take effect when Mode is `file` or `volume`, both work when Rotation is `daily` or `size`. |
| 31 | + KeepDays int `json:",optional"` |
| 32 | + // StackCooldownMillis represents the cooldown time for stack logging, default is 100ms. |
| 33 | + StackCooldownMillis int `json:",default=100"` |
| 34 | + // MaxBackups represents how many backup log files will be kept. 0 means all files will be kept forever. |
| 35 | + // Only take effect when RotationRuleType is `size`. |
| 36 | + // Even though `MaxBackups` sets 0, log files will still be removed |
| 37 | + // if the `KeepDays` limitation is reached. |
| 38 | + MaxBackups int `json:",default=0"` |
| 39 | + // MaxSize represents how much space the writing log file takes up. 0 means no limit. The unit is `MB`. |
| 40 | + // Only take effect when RotationRuleType is `size` |
| 41 | + MaxSize int `json:",default=0"` |
| 42 | + // Rotation represents the type of log rotation rule. Default is `daily`. |
| 43 | + // daily: daily rotation. |
| 44 | + // size: size limited rotation. |
| 45 | + Rotation string `json:",default=daily,options=[daily,size]"` |
| 46 | + // FileTimeFormat represents the time format for file name, default is `2006-01-02T15:04:05.000Z07:00`. |
| 47 | + FileTimeFormat string `json:",optional"` |
| 48 | + // FieldKeys represents the field keys. |
| 49 | + FieldKeys fieldKeyConf `json:",optional"` |
| 50 | + } |
50 | 51 |
|
51 | | -type logKeyConf struct { |
52 | | - // CallerKey represents the caller key. |
53 | | - CallerKey string `json:",default=caller"` |
54 | | - // ContentKey represents the content key. |
55 | | - ContentKey string `json:",default=content"` |
56 | | - // DurationKey represents the duration key. |
57 | | - DurationKey string `json:",default=duration"` |
58 | | - // LevelKey represents the level key. |
59 | | - LevelKey string `json:",default=level"` |
60 | | - // SpanKey represents the span key. |
61 | | - SpanKey string `json:",default=span"` |
62 | | - // TimestampKey represents the timestamp key. |
63 | | - TimestampKey string `json:",default=@timestamp"` |
64 | | - // TraceKey represents the trace key. |
65 | | - TraceKey string `json:",default=trace"` |
66 | | - // TruncatedKey represents the truncated key. |
67 | | - TruncatedKey string `json:",default=truncated"` |
68 | | -} |
| 52 | + fieldKeyConf struct { |
| 53 | + // CallerKey represents the caller key. |
| 54 | + CallerKey string `json:",default=caller"` |
| 55 | + // ContentKey represents the content key. |
| 56 | + ContentKey string `json:",default=content"` |
| 57 | + // DurationKey represents the duration key. |
| 58 | + DurationKey string `json:",default=duration"` |
| 59 | + // LevelKey represents the level key. |
| 60 | + LevelKey string `json:",default=level"` |
| 61 | + // SpanKey represents the span key. |
| 62 | + SpanKey string `json:",default=span"` |
| 63 | + // TimestampKey represents the timestamp key. |
| 64 | + TimestampKey string `json:",default=@timestamp"` |
| 65 | + // TraceKey represents the trace key. |
| 66 | + TraceKey string `json:",default=trace"` |
| 67 | + // TruncatedKey represents the truncated key. |
| 68 | + TruncatedKey string `json:",default=truncated"` |
| 69 | + } |
| 70 | +) |
0 commit comments