log: add flush to log file (#5942)
parent
36352085ae
commit
7a4c27bd08
|
@ -49,25 +49,32 @@ pub fn (mut l Log) set_output_level(level Level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) set_full_logpath(full_log_path string) {
|
pub fn (mut l Log) set_full_logpath(full_log_path string) {
|
||||||
rlog_file := os.real_path( full_log_path )
|
rlog_file := os.real_path(full_log_path)
|
||||||
l.set_output_label( os.file_name( rlog_file ) )
|
l.set_output_label(os.file_name(rlog_file))
|
||||||
l.set_output_path( os.base_dir( rlog_file ) )
|
l.set_output_path(os.base_dir(rlog_file))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) set_output_label(label string){
|
pub fn (mut l Log) set_output_label(label string) {
|
||||||
l.output_label = label
|
l.output_label = label
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) set_output_path(output_file_path string) {
|
pub fn (mut l Log) set_output_path(output_file_path string) {
|
||||||
if l.ofile.is_opened() { l.ofile.close() }
|
if l.ofile.is_opened() {
|
||||||
|
l.ofile.close()
|
||||||
|
}
|
||||||
l.output_to_file = true
|
l.output_to_file = true
|
||||||
l.output_file_name = os.join_path( os.real_path( output_file_path ) , l.output_label )
|
l.output_file_name = os.join_path(os.real_path(output_file_path), l.output_label)
|
||||||
ofile := os.open_append( l.output_file_name ) or {
|
ofile := os.open_append(l.output_file_name) or {
|
||||||
panic('error while opening log file ${l.output_file_name} for appending')
|
panic('error while opening log file $l.output_file_name for appending')
|
||||||
}
|
}
|
||||||
l.ofile = ofile
|
l.ofile = ofile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Writes the log file content to disk
|
||||||
|
pub fn (mut l Log) flush() {
|
||||||
|
l.ofile.flush()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) close() {
|
pub fn (mut l Log) close() {
|
||||||
l.ofile.close()
|
l.ofile.close()
|
||||||
}
|
}
|
||||||
|
@ -81,7 +88,7 @@ fn (mut l Log) log_file(s string, level Level) {
|
||||||
fn (l &Log) log_cli(s string, level Level) {
|
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 (mut l Log) send_output(s &string, level Level) {
|
fn (mut l Log) send_output(s &string, level Level) {
|
||||||
|
@ -92,29 +99,39 @@ fn (mut l Log) send_output(s &string, level Level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) fatal(s string){
|
pub fn (mut l Log) fatal(s string) {
|
||||||
if l.level < .fatal { return }
|
if l.level < .fatal {
|
||||||
|
return
|
||||||
|
}
|
||||||
l.send_output(s, .fatal)
|
l.send_output(s, .fatal)
|
||||||
l.ofile.close()
|
l.ofile.close()
|
||||||
panic('$l.output_label: $s')
|
panic('$l.output_label: $s')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) error(s string) {
|
pub fn (mut l Log) error(s string) {
|
||||||
if l.level < .error { return }
|
if l.level < .error {
|
||||||
|
return
|
||||||
|
}
|
||||||
l.send_output(s, .error)
|
l.send_output(s, .error)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) warn(s string) {
|
pub fn (mut l Log) warn(s string) {
|
||||||
if l.level < .warn { return }
|
if l.level < .warn {
|
||||||
|
return
|
||||||
|
}
|
||||||
l.send_output(s, .warn)
|
l.send_output(s, .warn)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) info(s string) {
|
pub fn (mut l Log) info(s string) {
|
||||||
if l.level < .info { return }
|
if l.level < .info {
|
||||||
|
return
|
||||||
|
}
|
||||||
l.send_output(s, .info)
|
l.send_output(s, .info)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut l Log) debug(s string) {
|
pub fn (mut l Log) debug(s string) {
|
||||||
if l.level < .debug { return }
|
if l.level < .debug {
|
||||||
|
return
|
||||||
|
}
|
||||||
l.send_output(s, .debug)
|
l.send_output(s, .debug)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue