diff options
-rwxr-xr-x | GradeBook_lib.tcl | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index 45866b9..41fa9f1 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -439,21 +439,50 @@ proc dbg {msg {category msg_level_critical} {location ""}} { set location " in $location" } switch $category { - msg_level_info {set msg_header "Info$location:"; set level 6} - msg_level_warning {set msg_header "Warning$location:"; set level 4} - msg_level_dbg {set msg_header "Debug$location:"; set level 3} - msg_level_log {set msg_header "Log$location:"; set level 2} - msg_level_critical {set msg_header "Error$location:"; set level 1} - default {set msg_header "Unknown$location:"; set level 0} + msg_level_info {set msg_header "Info$location:";} + msg_level_warning {set msg_header "Warning$location:";} + msg_level_dbg {set msg_header "Debug$location:";} + msg_level_log {set msg_header "Log$location:";} + msg_level_critical {set msg_header "Error$location:";} + default {set msg_header "Unknown$location:";} } + addLogEntry "dbg message level $msg_header" "$msg" "$category" +} + +proc addLogEntry {entryTitle entryContent {category msg_level_critical}} { + global GradebookServerConfig + global logEntry + + switch $category { + msg_level_info {set level 6} + msg_level_warning {set level 4} + msg_level_dbg {set level 3} + msg_level_log {set level 2} + msg_level_critical {set level 1} + default {set level 0} + } if { $level <= $GradebookServerConfig(verbosity_level) } { - set fid [open $GradebookServerConfig(log_file) a+] - puts $fid "$msg_header $msg" - close $fid + lappend logEntry "$entryTitle" [::json::write string "$entryContent"] } } +proc logEntryToLogFile {} { + global logEntry + + #::json::write indented false + set logEntryJsonString [json::write object {*}$logEntry] + rawTextToLogFile "$logEntryJsonString" +} + +proc rawTextToLogFile {{msg "Error: message is not specified"}} { + global GradebookServerConfig + + set fid [open $GradebookServerConfig(log_file) a+] + puts $fid "$msg" + close $fid +} + proc timestamp { } { return [clock format [clock seconds] -format "%Y-%m-%dT%H:%M:%S"] } |