mirror of
https://github.com/envmodules/modules.git
synced 2026-06-18 00:06:53 +08:00
Log messages at end of modulecmd processing
Create logfd and logging states to manage respectively logger pipe file descriptor and log enablement. Logging is disabled is logger command is an empty string or if there is no message to log. Logs are sent during the termination phase of the modulecmd process. Logger pipe is started for the duration of the flush operation only.
This commit is contained in:
@@ -1167,3 +1167,4 @@ mogui
|
||||
modulepathlist
|
||||
codename
|
||||
EVENTLIST
|
||||
logfd
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
# Runtime state properties (default value, proc to call to initialize state
|
||||
# value?)
|
||||
##nagelfar ignore +34 Found constant
|
||||
##nagelfar ignore +36 Found constant
|
||||
array set g_state_defs [list\
|
||||
autoinit {0}\
|
||||
clock_seconds {<undef> initStateClockSeconds}\
|
||||
@@ -39,6 +39,8 @@ array set g_state_defs [list\
|
||||
is_win {<undef> initStateIsWin}\
|
||||
kernelversion {<undef> {runCommand uname -v}}\
|
||||
lm_info_cached {0}\
|
||||
logfd {{} initStateLogfd}\
|
||||
logging {<undef> initStateLogging}\
|
||||
lsb_codename {<undef> {runCommand lsb_release -s -c}}\
|
||||
lsb_id {<undef> {runCommand lsb_release -s -i}}\
|
||||
lsb_release {<undef> {runCommand lsb_release -s -r}}\
|
||||
@@ -469,6 +471,32 @@ proc initStateReportfd {} {
|
||||
return $reportfd
|
||||
}
|
||||
|
||||
# Determine if logging need to be started
|
||||
proc initStateLogging {} {
|
||||
set logger_not_empty [string length [lindex [getConf logger] 0]]
|
||||
set something_to_log [info exists ::g_log_msg_list]
|
||||
return [expr {$logger_not_empty && $something_to_log}]
|
||||
}
|
||||
|
||||
# start logger pipe process with defined configuration
|
||||
proc initStateLogfd {} {
|
||||
# sets default fallback value
|
||||
lassign $::g_state_defs(logfd) logfd
|
||||
|
||||
# start logger at first call and only if enabled
|
||||
if {[getState logging]} {
|
||||
if {[catch {
|
||||
# drop output of logger command to avoid it pollutes main channels
|
||||
set logfd [open "|[getConf logger] >/dev/null 2>/dev/null" w]
|
||||
fconfigure $logfd -buffering none -blocking 1
|
||||
} errMsg]} {
|
||||
reportWarning $errMsg
|
||||
}
|
||||
}
|
||||
|
||||
return $logfd
|
||||
}
|
||||
|
||||
# Provide columns number for output formatting
|
||||
proc initStateTermColumns {} {
|
||||
set cols [getConf term_width]
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
proc flushAndExit {code} {
|
||||
# output all shell code generated on stdout
|
||||
renderFlush
|
||||
# send messages to log if any and enabled
|
||||
logFlush
|
||||
# output last messages on the report file descriptor and close it
|
||||
reportFlush
|
||||
|
||||
|
||||
@@ -791,6 +791,25 @@ proc reportFlush {} {
|
||||
}
|
||||
}
|
||||
|
||||
# send messages to log
|
||||
proc logFlush {} {
|
||||
# logger pipe is started only if enabled and some msgs need to be logged
|
||||
set logfd [getState logfd]
|
||||
|
||||
# logging only occurs from this procedure with is run during termination
|
||||
if {[string length $logfd]} {
|
||||
if {[catch {
|
||||
foreach log_msg $::g_log_msg_list {
|
||||
puts $logfd $log_msg
|
||||
}
|
||||
flush $logfd
|
||||
close $logfd
|
||||
} errMsg]} {
|
||||
reportWarning {Issue occurred when logging information}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# check if element passed as argument (corresponding to a kind of information)
|
||||
# should be part of output content
|
||||
proc isEltInReport {elt {retifnotdef 1}} {
|
||||
|
||||
Reference in New Issue
Block a user