log: fix log_to_file (#7955)
parent
b299fb1e92
commit
a481c1785b
|
@ -17,7 +17,7 @@ pub enum Level {
|
|||
}
|
||||
|
||||
// tag returns the tag for log level `l` as a string.
|
||||
fn tag(l Level) string {
|
||||
fn tag_to_cli(l Level) string {
|
||||
return match l {
|
||||
.fatal { term.red('FATAL') }
|
||||
.error { term.red('ERROR') }
|
||||
|
@ -27,6 +27,17 @@ fn tag(l Level) string {
|
|||
}
|
||||
}
|
||||
|
||||
// tag returns the tag for log level `l` as a string.
|
||||
fn tag_to_file(l Level) string {
|
||||
return match l {
|
||||
.fatal { 'FATAL' }
|
||||
.error { 'ERROR' }
|
||||
.warn { 'WARN ' }
|
||||
.info { 'INFO ' }
|
||||
.debug { 'DEBUG' }
|
||||
}
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
fatal(s string)
|
||||
error(s string)
|
||||
|
@ -94,13 +105,13 @@ pub fn (mut l Log) close() {
|
|||
// log_file writes log line `s` with `level` to the log file.
|
||||
fn (mut l Log) log_file(s string, level Level) {
|
||||
timestamp := time.now().format_ss()
|
||||
e := tag(level)
|
||||
e := tag_to_file(level)
|
||||
l.ofile.writeln('$timestamp [$e] $s')
|
||||
}
|
||||
|
||||
// log_cli writes log line `s` with `level` to stdout.
|
||||
fn (l &Log) log_cli(s string, level Level) {
|
||||
f := tag(level)
|
||||
f := tag_to_cli(level)
|
||||
t := time.now()
|
||||
println('[$f $t.format_ss()] $s')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue