mirror of
https://github.com/gechandesu/structlog.git
synced 2026-02-13 08:41:53 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6d53758b3 | |||
| a9a0e22d3a | |||
| f688b3cad5 |
@@ -4,7 +4,6 @@ import structlog
|
||||
fn main() {
|
||||
// Initialize logger with edited timestamp.
|
||||
log := structlog.new(
|
||||
// timestamp_format: .unix
|
||||
timestamp: structlog.Timestamp{
|
||||
format: .unix
|
||||
}
|
||||
|
||||
40
structlog.v
40
structlog.v
@@ -96,9 +96,8 @@ pub fn (r Record) append(field ...Field) Record {
|
||||
mut fields_orig := unsafe { r.fields }
|
||||
fields_orig << field
|
||||
return Record{
|
||||
channel: r.channel
|
||||
level: r.level
|
||||
fields: &fields_orig
|
||||
...r
|
||||
fields: &fields_orig
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +109,8 @@ pub fn (r Record) prepend(field ...Field) Record {
|
||||
mut new_fields := unsafe { field }
|
||||
new_fields << r.fields
|
||||
return Record{
|
||||
channel: r.channel
|
||||
level: r.level
|
||||
fields: new_fields
|
||||
...r
|
||||
fields: new_fields
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,9 +144,9 @@ pub fn (r Record) send() {
|
||||
|
||||
pub struct Timestamp {
|
||||
pub mut:
|
||||
// format sets the format of datettime for logs.
|
||||
// TimestampFormat values map 1-to-1 to the date formats provided by `time.Time`.
|
||||
// If .custom format is selected the timestamp_custom field must be set.
|
||||
// format sets the format of datetime in logs. TimestampFormat values
|
||||
// map 1-to-1 to the date formats provided by `time.Time`.
|
||||
// If .custom format is selected the `custom` field must be set.
|
||||
format TimestampFormat = .rfc3339
|
||||
|
||||
// custom sets the custom datetime string format if format is set to .custom.
|
||||
@@ -192,18 +190,6 @@ pub:
|
||||
add_level bool = true // if true add `level` field to all log records.
|
||||
add_timestamp bool = true // if true add `timestamp` field to all log records.
|
||||
|
||||
// timestamp_format sets the format of datettime for logs.
|
||||
// TimestampFormat values map 1-to-1 to the date formats provided by `time.Time`.
|
||||
// If .custom format is selected the timestamp_custom field must be set.
|
||||
timestamp_format TimestampFormat = .rfc3339 @[deprecated: 'use `timestamp` instead']
|
||||
|
||||
// timestamp_custom sets the custom datetime string format if timestapm_format is
|
||||
// set to .custom. See docs for Time.format_custom() fn from stadnard `time` module.
|
||||
timestamp_custom string @[deprecated: 'use `timestamp` instead']
|
||||
|
||||
// If timestamp_local is true the local time will be used instead of UTC.
|
||||
timestamp_local bool @[deprecated: 'use `timestamp` instead']
|
||||
|
||||
// handler holds a log record handler object which is used to process logs.
|
||||
handler RecordHandler = TextHandler{
|
||||
writer: os.stdout()
|
||||
@@ -261,20 +247,10 @@ pub fn new(config LogConfig) StructuredLog {
|
||||
|
||||
mut extra_fields := []Field{}
|
||||
|
||||
mut timestamp := logger.timestamp
|
||||
mut timestamp_old := Timestamp{
|
||||
format: logger.timestamp_format
|
||||
custom: logger.timestamp_custom
|
||||
local: logger.timestamp_local
|
||||
}
|
||||
if timestamp != timestamp_old {
|
||||
timestamp = timestamp_old
|
||||
}
|
||||
|
||||
if logger.add_timestamp {
|
||||
extra_fields << Field{
|
||||
name: 'timestamp'
|
||||
value: timestamp.as_value()
|
||||
value: logger.timestamp.as_value()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user