2019-06-26 03:14:38 +03:00
|
|
|
module log
|
|
|
|
|
2019-07-01 18:09:22 +03:00
|
|
|
import term
|
2019-06-26 03:14:38 +03:00
|
|
|
|
|
|
|
const (
|
|
|
|
FATAL = 1
|
|
|
|
ERROR = 2
|
|
|
|
WARN = 3
|
|
|
|
INFO = 4
|
|
|
|
DEBUG =5
|
|
|
|
)
|
|
|
|
|
|
|
|
struct Log{
|
|
|
|
mut:
|
|
|
|
level int
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn (l mut Log) set_level(level int){
|
|
|
|
l.level = level
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (l Log) fatal(s string){
|
|
|
|
panic(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (l Log) error(s string){
|
|
|
|
if l.level >= ERROR{
|
2019-07-01 18:09:22 +03:00
|
|
|
f := term.red('E')
|
2019-06-26 03:14:38 +03:00
|
|
|
println('[$f]$s')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (l Log) warn(s string){
|
|
|
|
if l.level >= WARN{
|
2019-07-01 18:09:22 +03:00
|
|
|
f := term.yellow('W')
|
2019-06-26 03:14:38 +03:00
|
|
|
println('[$f]$s')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (l Log) info(s string){
|
|
|
|
if l.level >= INFO{
|
2019-07-01 18:09:22 +03:00
|
|
|
f := term.white('I')
|
2019-06-26 03:14:38 +03:00
|
|
|
println('[$f]$s')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (l Log) debug(s string){
|
|
|
|
if l.level >= DEBUG{
|
2019-07-01 18:09:22 +03:00
|
|
|
f := term.blue('D')
|
2019-06-26 03:14:38 +03:00
|
|
|
println('[$f]$s')
|
|
|
|
}
|
2019-07-01 18:09:22 +03:00
|
|
|
}
|