Skip to content

Commit

Permalink
doc: fix logging sys on log-module-command recipe
Browse files Browse the repository at this point in the history
Update log-module-command recipe to ensure the logging system is not
broken by the current user environment.

Fixes #475.
  • Loading branch information
xdelaruelle committed Oct 14, 2022
1 parent 470d922 commit 52fda47
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .aspell.en.pws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 852
personal_ws-1.1 en 853
ABBRVLIST
ActiveTcl
Adrien
Expand Down Expand Up @@ -378,6 +378,7 @@ etcdir
eu
eval
exe
execLogger
execcmdlist
executables
execve
Expand Down
2 changes: 2 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Modules 5.2.0 (not yet released)
* Add :subcmd:`stashlist` sub-command to list all stash collection files.
* Update :subcmd:`savelist` sub-command to filter out stash collections unless
if :option:`--all` option is set.
* Doc: ensure current user environment does not break logging system in
:ref:`log-module-command` recipe. (fix issue #475)

.. _Nagelfar: http://nagelfar.sourceforge.net/
.. _ShellCheck: https://www.shellcheck.net/
Expand Down
21 changes: 17 additions & 4 deletions doc/example/log-module-commands/siteconfig.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
# installation. Refer to the "Modulecmd startup" section in the
# module(1) man page to get this location.

proc execLogger {msg} {
# ensure logger command is executed with system libs
if {[info exists ::env(LD_LIBRARY_PATH)]} {
set ORIG_LD_LIBRARY_PATH $::env(LD_LIBRARY_PATH)
unset ::env(LD_LIBRARY_PATH)
}
exec logger -t module $msg
# restore current user lib setup
if {[info exists ORIG_LD_LIBRARY_PATH]} {
set ::env(LD_LIBRARY_PATH) $ORIG_LD_LIBRARY_PATH
}
}

proc logModfileInterp {cmdstring code result op} {
# parse context
lassign $cmdstring cmdname modfile modname
Expand All @@ -32,8 +45,8 @@ proc logModfileInterp {cmdstring code result op} {
}

# produced log entry (formatted as a JSON record)
exec logger -t module "{ \"user\": \"[get-env USER]\", \"mode\":\
\"$mode\", \"module\": \"$modname\"${extra} }"
execLogger "{ \"user\": \"[get-env USER]\", \"mode\": \"$mode\",\
\"module\": \"$modname\"${extra} }"
}
}

Expand All @@ -53,8 +66,8 @@ proc logModuleCmd {cmdstring code result op} {
if {$cmdname ne {module} || $caller ne {ml}} {

# produced log entry (formatted as a JSON record)
exec logger -t module "{ \"user\": \"[get-env USER]\", \"cmd\":\
\"$cmdname\", \"args\": \"$args\" }"
execLogger "{ \"user\": \"[get-env USER]\", \"cmd\": \"$cmdname\",\
\"args\": \"$args\" }"
}
}

Expand Down
35 changes: 22 additions & 13 deletions doc/source/cookbook/log-module-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ configuration that traces every call to a modulefile evaluation.
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:caption: siteconfig.tcl
:lines: 13-41
:lineno-start: 13
:lines: 26-54
:lineno-start: 26

This code defines a ``logModfileInterp`` procedure which is set to be
evaluated after each evaluation of the ``execute-modulefile`` procedure with
Expand All @@ -32,19 +32,28 @@ following line:

.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:lines: 23-24
:lineno-start: 23
:lines: 36-37
:lineno-start: 36

In the proposed code, log entries are formatted as a JSON record which is
convenient to push these logs in a search and analytics engine like
`Elasticsearch`_ or `Splunk`_. Such tools help to globally monitor the whole
set of log entries produced from thousands of computing nodes.

.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:lines: 47-49
:lineno-start: 47

In the proposed code, the :command:`logger` command is run to generate a log
message. Log entries are formatted as a JSON record which is convenient to
push these logs in a search and analytics engine like `Elasticsearch`_ or
`Splunk`_. Such tools help to globally monitor the whole set of log entries
produced from thousands of computing nodes.
The :command:`logger` command is run to generate the log message. This is done
through a specific ``execLogger`` procedure ensuring that the current user
environment does not confuse :command:`logger` with unexpected version of the
libraries it requires.

.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:lines: 34-36
:lineno-start: 34
:lines: 13-24
:lineno-start: 13

Example code also defines a ``logModuleCmd`` procedure which is set to be
evaluated after each evaluation of the ``module`` and the ``ml`` procedures
Expand All @@ -53,8 +62,8 @@ with `trace`_ Tcl command.
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:caption: siteconfig.tcl
:lines: 43-63
:lineno-start: 43
:lines: 56-76
:lineno-start: 56

.. note::

Expand Down

0 comments on commit 52fda47

Please sign in to comment.