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:
Mahmoud-Emad
2025-09-18 17:29:11 +03:00
parent b83aa75e9d
commit f54c57847a
8 changed files with 300 additions and 26 deletions

View File

@@ -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}')
}
}
}