1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

log: extended logging level names when printed

This commit is contained in:
Major Taylor 2020-02-29 08:31:59 -05:00 committed by GitHub
parent f9d5c0110f
commit d4b0de2dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,11 @@
module log
import os
import time
import term
import filepath
import (
os
time
term
filepath
)
pub enum LogLevel {
fatal = 1
@ -15,11 +17,11 @@ pub enum LogLevel {
fn tag(l LogLevel) string {
return match l {
.fatal { term.red('F') }
.error { term.red('E') }
.warn { term.yellow('W') }
.info { term.white('I') }
.debug { term.blue('D') }
.fatal { term.red('FATAL') }
.error { term.red('ERROR') }
.warn { term.yellow('WARN ') }
.info { term.white('INFO ') }
.debug { term.blue('DEBUG') }
else { ' ' }
}
}
@ -50,7 +52,7 @@ pub mut:
output_file_name string
}
pub fn (l mut Log) set_level(level int){
pub fn (l mut Log) set_level(level int) {
l.level = match level {
FATAL { LogLevel.fatal }
ERROR { LogLevel.error }
@ -61,7 +63,7 @@ pub fn (l mut Log) set_level(level int){
}
}
pub fn (l mut Log) set_output_level(level LogLevel){
pub fn (l mut Log) set_output_level(level LogLevel) {
l.level = level
}
@ -85,7 +87,7 @@ pub fn (l mut Log) set_output_path(output_file_path string) {
l.ofile = ofile
}
pub fn (l mut Log) close(){
pub fn (l mut Log) close() {
l.ofile.close()
}
@ -101,7 +103,7 @@ fn (l &Log) log_cli(s string, level LogLevel) {
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 LogLevel) {
if l.output_to_file {
l.log_file(s, level)
} else {
@ -116,22 +118,22 @@ pub fn (l mut Log) fatal(s string){
panic('$l.output_label: $s')
}
pub fn (l mut Log) error(s string){
pub fn (l mut Log) error(s string) {
if l.level < .error { return }
l.send_output(s, .error)
}
pub fn (l mut Log) warn(s string){
pub fn (l mut Log) warn(s string) {
if l.level < .warn { return }
l.send_output(s, .warn)
}
pub fn (l mut Log) info(s string){
pub fn (l mut Log) info(s string) {
if l.level < .info { return }
l.send_output(s, .info)
}
pub fn (l mut Log) debug(s string){
pub fn (l mut Log) debug(s string) {
if l.level < .debug { return }
l.send_output(s, .debug)
}