log: fix example error
parent
2006995020
commit
4d5fe14968
|
@ -143,7 +143,7 @@ fn main() {
|
||||||
// new GenVC
|
// new GenVC
|
||||||
fn new_gen_vc(flag_options FlagOptions) &GenVC {
|
fn new_gen_vc(flag_options FlagOptions) &GenVC {
|
||||||
mut logger := &log.Log{}
|
mut logger := &log.Log{}
|
||||||
logger.set_level(log.DEBUG)
|
logger.set_level(.debug)
|
||||||
if flag_options.log_to == 'file' {
|
if flag_options.log_to == 'file' {
|
||||||
logger.set_full_logpath( flag_options.log_file )
|
logger.set_full_logpath( flag_options.log_file )
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import log
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut l := log.Log{}
|
mut l := log.Log{}
|
||||||
l.set_level(log.INFO)
|
l.set_level(.info)
|
||||||
// Make a new file called info.log in the current folder
|
// Make a new file called info.log in the current folder
|
||||||
l.set_full_logpath('./info.log')
|
l.set_full_logpath('./info.log')
|
||||||
println('Please check the file: ${l.output_file_name} after this example crashes.')
|
println('Please check the file: ${l.output_file_name} after this example crashes.')
|
||||||
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
l.warn('warn')
|
l.warn('warn')
|
||||||
l.error('error')
|
l.error('error')
|
||||||
l.debug('no debug')
|
l.debug('no debug')
|
||||||
l.set_level(log.DEBUG)
|
l.set_level(.debug)
|
||||||
l.debug('debug')
|
l.debug('debug')
|
||||||
l.fatal('fatal')
|
l.fatal('fatal')
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
term
|
term
|
||||||
)
|
)
|
||||||
|
|
||||||
pub enum LogLevel {
|
pub enum Level {
|
||||||
fatal = 1
|
fatal = 1
|
||||||
error
|
error
|
||||||
warn
|
warn
|
||||||
|
@ -14,7 +14,7 @@ pub enum LogLevel {
|
||||||
debug
|
debug
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tag(l LogLevel) string {
|
fn tag(l Level) string {
|
||||||
return match l {
|
return match l {
|
||||||
.fatal { term.red('FATAL') }
|
.fatal { term.red('FATAL') }
|
||||||
.error { term.red('ERROR') }
|
.error { term.red('ERROR') }
|
||||||
|
@ -25,14 +25,6 @@ fn tag(l LogLevel) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const (
|
|
||||||
FATAL = 1
|
|
||||||
ERROR = 2
|
|
||||||
WARN = 3
|
|
||||||
INFO = 4
|
|
||||||
DEBUG = 5
|
|
||||||
)
|
|
||||||
|
|
||||||
interface Logger {
|
interface Logger {
|
||||||
fatal(s string)
|
fatal(s string)
|
||||||
error(s string)
|
error(s string)
|
||||||
|
@ -43,7 +35,7 @@ interface Logger {
|
||||||
|
|
||||||
pub struct Log {
|
pub struct Log {
|
||||||
mut:
|
mut:
|
||||||
level LogLevel
|
level Level
|
||||||
output_label string
|
output_label string
|
||||||
ofile os.File
|
ofile os.File
|
||||||
output_to_file bool
|
output_to_file bool
|
||||||
|
@ -51,18 +43,11 @@ pub mut:
|
||||||
output_file_name string
|
output_file_name string
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (l mut Log) set_level(level int) {
|
pub fn (l mut Log) set_level(level Level) {
|
||||||
l.level = match level {
|
l.level = level
|
||||||
FATAL { LogLevel.fatal }
|
|
||||||
ERROR { LogLevel.error }
|
|
||||||
WARN { LogLevel.warn }
|
|
||||||
INFO { LogLevel.info }
|
|
||||||
DEBUG { LogLevel.debug }
|
|
||||||
else { .debug }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (l mut Log) set_output_level(level LogLevel) {
|
pub fn (l mut Log) set_output_level(level Level) {
|
||||||
l.level = level
|
l.level = level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,19 +75,19 @@ pub fn (l mut Log) close() {
|
||||||
l.ofile.close()
|
l.ofile.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (l mut Log) log_file(s string, level LogLevel) {
|
fn (l mut Log) log_file(s string, level Level) {
|
||||||
timestamp := time.now().format_ss()
|
timestamp := time.now().format_ss()
|
||||||
e := tag(level)
|
e := tag(level)
|
||||||
l.ofile.writeln('$timestamp [$e] $s')
|
l.ofile.writeln('$timestamp [$e] $s')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (l &Log) log_cli(s string, level LogLevel) {
|
fn (l &Log) log_cli(s string, level Level) {
|
||||||
f := tag(level)
|
f := tag(level)
|
||||||
t := time.now()
|
t := time.now()
|
||||||
println('[$f ${t.format_ss()}] $s')
|
println('[$f ${t.format_ss()}] $s')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (l mut Log) send_output(s &string, level LogLevel) {
|
fn (l mut Log) send_output(s &string, level Level) {
|
||||||
if l.output_to_file {
|
if l.output_to_file {
|
||||||
l.log_file(s, level)
|
l.log_file(s, level)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import benchmark
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut logger := log.Log{}
|
mut logger := log.Log{}
|
||||||
logger.set_level(log.DEBUG)
|
logger.set_level(.debug)
|
||||||
options := runner.new_options()
|
options := runner.new_options()
|
||||||
mut bmark := benchmark.new_benchmark()
|
mut bmark := benchmark.new_benchmark()
|
||||||
for file in options.files {
|
for file in options.files {
|
||||||
|
|
Loading…
Reference in New Issue