From 2fd9623ee1779a78aa3e7f8a1cc5851618f67324 Mon Sep 17 00:00:00 2001 From: Hitalo Souza Date: Sat, 26 Oct 2024 07:40:54 -0400 Subject: [PATCH 01/11] perf: log --- vlib/log/log.v | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index cedeb0cd5981be..ea01f2f698e466 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -8,12 +8,12 @@ import time // TimeFormat define the log time string format, come from time/format.v pub enum TimeFormat { - tf_ss_micro // YYYY-MM-DD HH:mm:ss.123456 (24h) default + tf_ss_micro // YYYY-MM-DD HH:mm:ss.123456 (24h) tf_default // YYYY-MM-DD HH:mm (24h) tf_ss // YYYY-MM-DD HH:mm:ss (24h) tf_ss_milli // YYYY-MM-DD HH:mm:ss.123 (24h) tf_ss_nano // YYYY-MM-DD HH:mm:ss.123456789 (24h) - tf_rfc3339 // YYYY-MM-DDTHH:mm:ss.123Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) + tf_rfc3339 // YYYY-MM-DDTHH:mm:ss.123Z default (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_rfc3339_nano // YYYY-MM-DDTHH:mm:ss.123456789Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_hhmm // HH:mm (24h) tf_hhmmss // HH:mm:ss (24h) @@ -24,6 +24,25 @@ pub enum TimeFormat { tf_custom_format // 'MMMM Do YY N kk:mm:ss A' output like: January 1st 22 AD 13:45:33 PM } +pub fn (l &Log) get_time_string_len() int { + match l.time_format { + .tf_ss_micro { return 26 } + .tf_default { return 16 } + .tf_ss { return 19 } + .tf_ss_milli { return 23 } + .tf_ss_nano { return 29 } + .tf_rfc3339 { return 24 } + .tf_rfc3339_nano { return 30 } + .tf_hhmm { return 5 } + .tf_hhmmss { return 8 } + .tf_hhmm12 { return 5 } + .tf_ymmdd { return 10 } + .tf_ddmmy { return 10 } + .tf_md { return 7 } + .tf_custom_format { return 30 } + } +} + // Log represents a logging object pub struct Log { mut: @@ -31,8 +50,8 @@ mut: output_label string ofile os.File output_target LogTarget // output to console (stdout/stderr) or file or both. - time_format TimeFormat - custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format + time_format TimeFormat = .tf_rfc3339 + custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format short_tag bool always_flush bool // flush after every single .fatal(), .error(), .warn(), .info(), .debug() call pub mut: @@ -116,9 +135,17 @@ pub fn (mut l Log) reopen() ! { // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { - timestamp := l.time_format(time.now()) + timestamp := l.time_format(time.utc()) e := tag_to_file(level, l.short_tag) - l.ofile.writeln('${timestamp} [${e}] ${s}') or { panic(err) } + + unsafe { + space := ' ' + l.ofile.write_ptr(timestamp.str, timestamp.len) + l.ofile.write_ptr(space.str, space.len) + l.ofile.write_ptr(e.str, e.len) + l.ofile.write_ptr(space.str, space.len) + l.ofile.write_ptr(s.str, s.len) + } if l.always_flush { l.flush() } @@ -126,7 +153,7 @@ fn (mut l Log) log_file(s string, level Level) { // log_cli writes log line `s` with `level` to stdout. fn (l &Log) log_cli(s string, level Level) { - timestamp := l.time_format(time.now()) + timestamp := l.time_format(time.utc()) e := tag_to_cli(level, l.short_tag) println('${timestamp} [${e}] ${s}') if l.always_flush { From a2255f6c78b80b3db75a9fc007a9f2b429e5d736 Mon Sep 17 00:00:00 2001 From: Hitalo Souza Date: Sat, 26 Oct 2024 08:16:35 -0400 Subject: [PATCH 02/11] doc: fix --- vlib/log/log.v | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index ea01f2f698e466..658ffb9d8cb202 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -24,7 +24,8 @@ pub enum TimeFormat { tf_custom_format // 'MMMM Do YY N kk:mm:ss A' output like: January 1st 22 AD 13:45:33 PM } -pub fn (l &Log) get_time_string_len() int { +// get_time_string_len returns the length of the time string for the given time format +fn (l &Log) get_time_string_len() int { match l.time_format { .tf_ss_micro { return 26 } .tf_default { return 16 } @@ -135,16 +136,17 @@ pub fn (mut l Log) reopen() ! { // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { - timestamp := l.time_format(time.utc()) - e := tag_to_file(level, l.short_tag) + // timestamp := l.time_format(time.utc()) + // e := tag_to_file(level, l.short_tag) unsafe { - space := ' ' - l.ofile.write_ptr(timestamp.str, timestamp.len) - l.ofile.write_ptr(space.str, space.len) - l.ofile.write_ptr(e.str, e.len) - l.ofile.write_ptr(space.str, space.len) + // space := ' ' + // l.ofile.write_ptr(timestamp.str, timestamp.len) + // l.ofile.write_ptr(space.str, space.len) + // l.ofile.write_ptr(e.str, e.len) + // l.ofile.write_ptr(space.str, space.len) l.ofile.write_ptr(s.str, s.len) + l.ofile.write_ptr('\n'.str, 1) } if l.always_flush { l.flush() From b73e6114eeb35de5674fed906c991fc39830b905 Mon Sep 17 00:00:00 2001 From: Hitalo Souza Date: Sat, 26 Oct 2024 08:19:32 -0400 Subject: [PATCH 03/11] fix: uncomment --- vlib/log/log.v | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index 658ffb9d8cb202..7ccd5900f372a1 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -136,15 +136,15 @@ pub fn (mut l Log) reopen() ! { // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { - // timestamp := l.time_format(time.utc()) - // e := tag_to_file(level, l.short_tag) + timestamp := l.time_format(time.utc()) + e := tag_to_file(level, l.short_tag) unsafe { - // space := ' ' - // l.ofile.write_ptr(timestamp.str, timestamp.len) - // l.ofile.write_ptr(space.str, space.len) - // l.ofile.write_ptr(e.str, e.len) - // l.ofile.write_ptr(space.str, space.len) + space := ' ' + l.ofile.write_ptr(timestamp.str, timestamp.len) + l.ofile.write_ptr(space.str, space.len) + l.ofile.write_ptr(e.str, e.len) + l.ofile.write_ptr(space.str, space.len) l.ofile.write_ptr(s.str, s.len) l.ofile.write_ptr('\n'.str, 1) } From 649053e96f928241a3beda834effd73929b75d53 Mon Sep 17 00:00:00 2001 From: Hitalo Souza Date: Sat, 26 Oct 2024 08:25:18 -0400 Subject: [PATCH 04/11] fix --- vlib/log/log.v | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vlib/log/log.v b/vlib/log/log.v index 7ccd5900f372a1..42e7f56fd6f304 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -143,9 +143,14 @@ fn (mut l Log) log_file(s string, level Level) { space := ' ' l.ofile.write_ptr(timestamp.str, timestamp.len) l.ofile.write_ptr(space.str, space.len) + + l.ofile.write_ptr('['.str, 1) l.ofile.write_ptr(e.str, e.len) + l.ofile.write_ptr(']'.str, 1) + l.ofile.write_ptr(space.str, space.len) l.ofile.write_ptr(s.str, s.len) + l.ofile.write_ptr('\n'.str, 1) } if l.always_flush { From aa283603aa78318cd11c4b192a2acdb80032e2ed Mon Sep 17 00:00:00 2001 From: Hitalo Souza Date: Sat, 26 Oct 2024 08:46:26 -0400 Subject: [PATCH 05/11] fix --- vlib/log/log.v | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index 42e7f56fd6f304..a1a1c014c2169d 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -8,12 +8,12 @@ import time // TimeFormat define the log time string format, come from time/format.v pub enum TimeFormat { - tf_ss_micro // YYYY-MM-DD HH:mm:ss.123456 (24h) + tf_ss_micro // YYYY-MM-DD HH:mm:ss.123456 (24h) default tf_default // YYYY-MM-DD HH:mm (24h) tf_ss // YYYY-MM-DD HH:mm:ss (24h) tf_ss_milli // YYYY-MM-DD HH:mm:ss.123 (24h) tf_ss_nano // YYYY-MM-DD HH:mm:ss.123456789 (24h) - tf_rfc3339 // YYYY-MM-DDTHH:mm:ss.123Z default (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) + tf_rfc3339 // YYYY-MM-DDTHH:mm:ss.123Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_rfc3339_nano // YYYY-MM-DDTHH:mm:ss.123456789Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_hhmm // HH:mm (24h) tf_hhmmss // HH:mm:ss (24h) @@ -51,7 +51,7 @@ mut: output_label string ofile os.File output_target LogTarget // output to console (stdout/stderr) or file or both. - time_format TimeFormat = .tf_rfc3339 + time_format TimeFormat = .tf_ss_micro custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format short_tag bool always_flush bool // flush after every single .fatal(), .error(), .warn(), .info(), .debug() call From 389fa0e93376a6d6a0f5d80235d436129d90635e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Oct 2024 09:30:47 +0200 Subject: [PATCH 06/11] restore previous behaviour for everything, except Log.log_file --- vlib/log/log.v | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index a1a1c014c2169d..fa93dad7bbce38 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -51,8 +51,8 @@ mut: output_label string ofile os.File output_target LogTarget // output to console (stdout/stderr) or file or both. - time_format TimeFormat = .tf_ss_micro - custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format + time_format TimeFormat + custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format short_tag bool always_flush bool // flush after every single .fatal(), .error(), .warn(), .info(), .debug() call pub mut: @@ -136,7 +136,7 @@ pub fn (mut l Log) reopen() ! { // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { - timestamp := l.time_format(time.utc()) + timestamp := l.time_format(time.now()) e := tag_to_file(level, l.short_tag) unsafe { @@ -160,7 +160,7 @@ fn (mut l Log) log_file(s string, level Level) { // log_cli writes log line `s` with `level` to stdout. fn (l &Log) log_cli(s string, level Level) { - timestamp := l.time_format(time.utc()) + timestamp := l.time_format(time.now()) e := tag_to_cli(level, l.short_tag) println('${timestamp} [${e}] ${s}') if l.always_flush { From 292ce39ce6b6be9b211e3b90b2b3b8c3de8f8487 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Oct 2024 09:31:47 +0200 Subject: [PATCH 07/11] remove unused function too --- vlib/log/log.v | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index fa93dad7bbce38..18c04c18d42773 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -24,26 +24,6 @@ pub enum TimeFormat { tf_custom_format // 'MMMM Do YY N kk:mm:ss A' output like: January 1st 22 AD 13:45:33 PM } -// get_time_string_len returns the length of the time string for the given time format -fn (l &Log) get_time_string_len() int { - match l.time_format { - .tf_ss_micro { return 26 } - .tf_default { return 16 } - .tf_ss { return 19 } - .tf_ss_milli { return 23 } - .tf_ss_nano { return 29 } - .tf_rfc3339 { return 24 } - .tf_rfc3339_nano { return 30 } - .tf_hhmm { return 5 } - .tf_hhmmss { return 8 } - .tf_hhmm12 { return 5 } - .tf_ymmdd { return 10 } - .tf_ddmmy { return 10 } - .tf_md { return 7 } - .tf_custom_format { return 30 } - } -} - // Log represents a logging object pub struct Log { mut: From 60d434cf0eb8e946f1f3612e01933ea5608e3d99 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Oct 2024 09:54:51 +0200 Subject: [PATCH 08/11] use constants for the literals used as arguments to l.ofile.write_ptr --- vlib/log/log.v | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index 18c04c18d42773..9f9e4217f5d176 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -114,24 +114,28 @@ pub fn (mut l Log) reopen() ! { } } +const space = ' ' +const lbracket = '[' +const rbracket = ']' +const newline = '\n' + // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { timestamp := l.time_format(time.now()) e := tag_to_file(level, l.short_tag) unsafe { - space := ' ' l.ofile.write_ptr(timestamp.str, timestamp.len) l.ofile.write_ptr(space.str, space.len) - l.ofile.write_ptr('['.str, 1) + l.ofile.write_ptr(lbracket.str, 1) l.ofile.write_ptr(e.str, e.len) - l.ofile.write_ptr(']'.str, 1) + l.ofile.write_ptr(rbracket.str, 1) l.ofile.write_ptr(space.str, space.len) l.ofile.write_ptr(s.str, s.len) - l.ofile.write_ptr('\n'.str, 1) + l.ofile.write_ptr(newline.str, 1) } if l.always_flush { l.flush() From 339c3453b454ed0699a421a0e387db9f7b2ff4d4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Oct 2024 10:20:03 +0200 Subject: [PATCH 09/11] time: add Time.format_rfc3339_micro, use it as the default timestamp format in `log` --- vlib/log/log.v | 12 ++++++++---- vlib/time/format.v | 33 +++++++++++++++++++++++++++++++++ vlib/time/time_test.v | 12 ++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index 9f9e4217f5d176..e55a025414d71c 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -14,6 +14,7 @@ pub enum TimeFormat { tf_ss_milli // YYYY-MM-DD HH:mm:ss.123 (24h) tf_ss_nano // YYYY-MM-DD HH:mm:ss.123456789 (24h) tf_rfc3339 // YYYY-MM-DDTHH:mm:ss.123Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) + tf_rfc3339_micro // YYYY-MM-DDTHH:mm:ss.123456Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_rfc3339_nano // YYYY-MM-DDTHH:mm:ss.123456789Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_hhmm // HH:mm (24h) tf_hhmmss // HH:mm:ss (24h) @@ -31,8 +32,8 @@ mut: output_label string ofile os.File output_target LogTarget // output to console (stdout/stderr) or file or both. - time_format TimeFormat - custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format + time_format TimeFormat = .tf_rfc3339_micro + custom_time_format string = 'MMMM Do YY N kk:mm:ss A' // timestamp with custom format short_tag bool always_flush bool // flush after every single .fatal(), .error(), .warn(), .info(), .debug() call pub mut: @@ -121,7 +122,7 @@ const newline = '\n' // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { - timestamp := l.time_format(time.now()) + timestamp := l.time_format(time.utc()) e := tag_to_file(level, l.short_tag) unsafe { @@ -144,7 +145,7 @@ fn (mut l Log) log_file(s string, level Level) { // log_cli writes log line `s` with `level` to stdout. fn (l &Log) log_cli(s string, level Level) { - timestamp := l.time_format(time.now()) + timestamp := l.time_format(time.utc()) e := tag_to_cli(level, l.short_tag) println('${timestamp} [${e}] ${s}') if l.always_flush { @@ -237,6 +238,9 @@ fn (l Log) time_format(t time.Time) string { .tf_rfc3339 { // YYYY-MM-DDTHH:mm:ss.123Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) return t.format_rfc3339() } + .tf_rfc3339_micro { // YYYY-MM-DDTHH:mm:ss.123456Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) + return t.format_rfc3339_micro() + } .tf_rfc3339_nano { // YYYY-MM-DDTHH:mm:ss.123456789Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) return t.format_rfc3339_nano() } diff --git a/vlib/time/format.v b/vlib/time/format.v index e4e759c510dc3e..56d1dcceb24091 100644 --- a/vlib/time/format.v +++ b/vlib/time/format.v @@ -174,6 +174,39 @@ pub fn (t Time) format_rfc3339() string { return buf.bytestr() } +// format_rfc3339_micro returns a date string in "YYYY-MM-DDTHH:mm:ss.123456Z" format (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) +@[manualfree] +pub fn (t Time) format_rfc3339_micro() string { + mut buf := [u8(`0`), `0`, `0`, `0`, `-`, `0`, `0`, `-`, `0`, `0`, `T`, `0`, `0`, `:`, `0`, + `0`, `:`, `0`, `0`, `.`, `0`, `0`, `0`, `0`, `0`, `0`, `Z`] + + defer { + unsafe { buf.free() } + } + + t_ := time_with_unix(t) + if t_.is_local { + utc_time := t_.local_to_utc() + int_to_byte_array_no_pad(utc_time.year, mut buf, 4) + int_to_byte_array_no_pad(utc_time.month, mut buf, 7) + int_to_byte_array_no_pad(utc_time.day, mut buf, 10) + int_to_byte_array_no_pad(utc_time.hour, mut buf, 13) + int_to_byte_array_no_pad(utc_time.minute, mut buf, 16) + int_to_byte_array_no_pad(utc_time.second, mut buf, 19) + int_to_byte_array_no_pad(utc_time.nanosecond / 1000, mut buf, 26) + } else { + int_to_byte_array_no_pad(t_.year, mut buf, 4) + int_to_byte_array_no_pad(t_.month, mut buf, 7) + int_to_byte_array_no_pad(t_.day, mut buf, 10) + int_to_byte_array_no_pad(t_.hour, mut buf, 13) + int_to_byte_array_no_pad(t_.minute, mut buf, 16) + int_to_byte_array_no_pad(t_.second, mut buf, 19) + int_to_byte_array_no_pad(t_.nanosecond / 1000, mut buf, 26) + } + + return buf.bytestr() +} + // format_rfc3339_nano returns a date string in "YYYY-MM-DDTHH:mm:ss.123456789Z" format (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) @[manualfree] pub fn (t Time) format_rfc3339_nano() string { diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index 4a12fbb49241a4..1185152d2e75b8 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -108,6 +108,18 @@ fn test_format_rfc3339() { assert utc_res.contains('T') } +fn test_format_rfc3339_micro() { + res := local_time_to_test.format_rfc3339_micro() + assert res.ends_with('23:42.123456Z') + assert res.starts_with('1980-07-1') + assert res.contains('T') + + utc_res := utc_time_to_test.format_rfc3339_micro() + assert utc_res.ends_with('23:42.123456Z') + assert utc_res.starts_with('1980-07-1') + assert utc_res.contains('T') +} + fn test_format_rfc3339_nano() { res := local_time_to_test.format_rfc3339_nano() assert res.ends_with('23:42.123456789Z') From 0e2ce7421da656011f248968448bf905469f3d5a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Oct 2024 10:29:52 +0200 Subject: [PATCH 10/11] revert using separate constants, reorder Log.time_format so the default format is checked first --- vlib/log/log.v | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/vlib/log/log.v b/vlib/log/log.v index e55a025414d71c..bd8df0590643d4 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -8,13 +8,13 @@ import time // TimeFormat define the log time string format, come from time/format.v pub enum TimeFormat { - tf_ss_micro // YYYY-MM-DD HH:mm:ss.123456 (24h) default + tf_ss_micro // YYYY-MM-DD HH:mm:ss.123456 (24h) tf_default // YYYY-MM-DD HH:mm (24h) tf_ss // YYYY-MM-DD HH:mm:ss (24h) tf_ss_milli // YYYY-MM-DD HH:mm:ss.123 (24h) tf_ss_nano // YYYY-MM-DD HH:mm:ss.123456789 (24h) tf_rfc3339 // YYYY-MM-DDTHH:mm:ss.123Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) - tf_rfc3339_micro // YYYY-MM-DDTHH:mm:ss.123456Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) + tf_rfc3339_micro // default, YYYY-MM-DDTHH:mm:ss.123456Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_rfc3339_nano // YYYY-MM-DDTHH:mm:ss.123456789Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) tf_hhmm // HH:mm (24h) tf_hhmmss // HH:mm:ss (24h) @@ -115,11 +115,6 @@ pub fn (mut l Log) reopen() ! { } } -const space = ' ' -const lbracket = '[' -const rbracket = ']' -const newline = '\n' - // log_file writes log line `s` with `level` to the log file. fn (mut l Log) log_file(s string, level Level) { timestamp := l.time_format(time.utc()) @@ -127,16 +122,16 @@ fn (mut l Log) log_file(s string, level Level) { unsafe { l.ofile.write_ptr(timestamp.str, timestamp.len) - l.ofile.write_ptr(space.str, space.len) + l.ofile.write_ptr(' '.str, 1) - l.ofile.write_ptr(lbracket.str, 1) + l.ofile.write_ptr('['.str, 1) l.ofile.write_ptr(e.str, e.len) - l.ofile.write_ptr(rbracket.str, 1) + l.ofile.write_ptr(']'.str, 1) - l.ofile.write_ptr(space.str, space.len) + l.ofile.write_ptr(' '.str, 1) l.ofile.write_ptr(s.str, s.len) - l.ofile.write_ptr(newline.str, 1) + l.ofile.write_ptr('\n'.str, 1) } if l.always_flush { l.flush() @@ -220,6 +215,9 @@ pub fn (mut f Log) free() { // time_format return a timestamp string in the pre-defined format fn (l Log) time_format(t time.Time) string { match l.time_format { + .tf_rfc3339_micro { // YYYY-MM-DDTHH:mm:ss.123456Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) + return t.format_rfc3339_micro() + } .tf_ss_micro { // YYYY-MM-DD HH:mm:ss.123456 (24h) default return t.format_ss_micro() } @@ -238,9 +236,6 @@ fn (l Log) time_format(t time.Time) string { .tf_rfc3339 { // YYYY-MM-DDTHH:mm:ss.123Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) return t.format_rfc3339() } - .tf_rfc3339_micro { // YYYY-MM-DDTHH:mm:ss.123456Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) - return t.format_rfc3339_micro() - } .tf_rfc3339_nano { // YYYY-MM-DDTHH:mm:ss.123456789Z (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html) return t.format_rfc3339_nano() } From 65eca1555b26420cca3998a199f0915784c288c4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Oct 2024 10:54:00 +0200 Subject: [PATCH 11/11] fix dump_expression.out to match the new default --- vlib/v/slow_tests/inout/dump_expression.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vlib/v/slow_tests/inout/dump_expression.out b/vlib/v/slow_tests/inout/dump_expression.out index 64fe20c6501c62..dc681e7a89676c 100644 --- a/vlib/v/slow_tests/inout/dump_expression.out +++ b/vlib/v/slow_tests/inout/dump_expression.out @@ -10,7 +10,7 @@ is_opened: false } output_target: console - time_format: tf_ss_micro + time_format: tf_rfc3339_micro custom_time_format: 'MMMM Do YY N kk:mm:ss A' short_tag: false always_flush: false