feat: Enhance logging and CORS handling
- Add console output option to logger - Implement ISO time conversion for calendar events - Add OPTIONS method for API and root handlers - Introduce health check endpoint with uptime and server info - Implement manual CORS handling in `before_request` - Add `start_time` to HeroServer for uptime tracking - Add `ServerLogParams` and `log` method for server logging
This commit is contained in:
@@ -5,13 +5,15 @@ import freeflowuniverse.herolib.core.pathlib
|
||||
// Logger Factory
|
||||
pub struct LoggerFactoryArgs {
|
||||
pub mut:
|
||||
path string
|
||||
path string
|
||||
console_output bool = true
|
||||
}
|
||||
|
||||
pub fn new(args LoggerFactoryArgs) !Logger {
|
||||
mut p := pathlib.get_dir(path: args.path, create: true)!
|
||||
return Logger{
|
||||
path: p
|
||||
lastlog_time: 0
|
||||
path: p
|
||||
lastlog_time: 0
|
||||
console_output: args.console_output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,26 @@ pub fn (mut l Logger) log(args_ LogItemArgs) ! {
|
||||
}
|
||||
f.writeln(content.trim_space_right())!
|
||||
f.close()
|
||||
|
||||
// Also write to console if enabled
|
||||
if l.console_output {
|
||||
l.write_to_console(args, t)!
|
||||
}
|
||||
}
|
||||
|
||||
// Write log message to console with clean formatting
|
||||
fn (mut l Logger) write_to_console(args LogItemArgs, t ourtime.OurTime) ! {
|
||||
timestamp := t.time().format_ss()
|
||||
error_indicator := if args.logtype == .error { 'ERROR' } else { 'INFO' }
|
||||
category := args.cat.trim_space()
|
||||
lines := args.log.split('\n')
|
||||
|
||||
for i, line in lines {
|
||||
if i == 0 {
|
||||
println('${timestamp} [${error_indicator}] [${category}] ${line}')
|
||||
} else {
|
||||
// Indent continuation lines
|
||||
println('${timestamp} [${error_indicator}] [${category}] ${line}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ import freeflowuniverse.herolib.core.pathlib
|
||||
@[heap]
|
||||
pub struct Logger {
|
||||
pub mut:
|
||||
path pathlib.Path
|
||||
lastlog_time i64 // to see in log format, every second we put a time down, we need to know if we are in a new second (logs can come in much faster)
|
||||
path pathlib.Path
|
||||
lastlog_time i64 // to see in log format, every second we put a time down, we need to know if we are in a new second (logs can come in much faster)
|
||||
console_output bool // whether to also output to console/stdout
|
||||
}
|
||||
|
||||
pub struct LogItem {
|
||||
|
||||
Reference in New Issue
Block a user