46 lines
762 B
V
46 lines
762 B
V
module core
|
|
|
|
import time
|
|
|
|
enum LogLevel {
|
|
info
|
|
debug
|
|
error
|
|
}
|
|
|
|
pub struct Logger {
|
|
mut:
|
|
logs string
|
|
}
|
|
|
|
fn log_level_str(level LogLevel) string {
|
|
return match level {
|
|
.info { 'INFO' }
|
|
.debug { 'DEBUG' }
|
|
.error { 'ERROR' }
|
|
}
|
|
}
|
|
|
|
pub fn (mut l Logger) log(mod string, level LogLevel, msg string) {
|
|
timestamp := time.now().format_ss_milli()
|
|
full_msg := '[$timestamp] [${log_level_str(level)}] [$mod] $msg'
|
|
|
|
println(full_msg)
|
|
|
|
l.logs += full_msg + '\n'
|
|
}
|
|
|
|
pub fn (mut l Logger) info(mod string, msg string) {
|
|
l.log(mod, .info, msg)
|
|
}
|
|
|
|
pub fn (mut l Logger) debug(mod string, msg string) {
|
|
l.log(mod, .debug, msg)
|
|
}
|
|
|
|
pub fn (mut l Logger) error(mod string, msg string) {
|
|
l.log(mod, .error, msg)
|
|
}
|
|
pub fn (l Logger) get_logs() string {
|
|
return l.logs
|
|
} |