Skip to content

Commit

Permalink
doc: fix log-module-command recipe siteconfig.tcl
Browse files Browse the repository at this point in the history
Fix the siteconfig.tcl file of the log-module-command cookbook recipe
not to break when a file is sourced through cmdModuleSource. Limit the
addition of the 'auto' log field only if load evaluation comes from
cmdModuleLoad procedure.

Fixes #453
  • Loading branch information
xdelaruelle committed Apr 28, 2022
1 parent fec3072 commit 9bff25c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 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 797
personal_ws-1.1 en 798
ABBRVLIST
ActiveTcl
Adrien
Expand All @@ -12,6 +12,7 @@ BASEPREFIX
BEFH
Booleans
Bourne
Burgue�o
CEST
CET
CFLAGS
Expand Down
3 changes: 3 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ Modules 5.1.0 (not yet released)
* When mentioning the loading, unloading or refreshing evaluation of a module,
report the tags associated to this module as done when printing results of
:subcmd:`list` sub-command.
* Fix :ref:`log-module-command` cookbook recipe not to break Modules
initialization when using provided :file:`siteconfig.tcl` file. (fix issue
#453 with contribution from Eric Burgueño)

.. _Code of conduct: https://github.com/cea-hpc/modules/blob/master/CODE_OF_CONDUCT.md
.. _codespell: https://github.com/codespell-project/codespell
Expand Down
7 changes: 6 additions & 1 deletion doc/example/log-module-commands/siteconfig.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ proc logModfileInterp {cmdstring code result op} {
# parse context
lassign $cmdstring cmdname modfile modname
set mode [currentState mode]
if {[info level] > 1} {
set caller [lindex [info level -1] 0]
} else {
set caller {}
}

# only log load and unload modulefile evaluation
if {$mode in {load unload}} {

# add info on load mode to know if module is auto-loaded or not
if {$mode eq {load}} {
if {$mode eq {load} && $caller eq {cmdModuleLoad}} {
upvar 1 uasked uasked
set extra ", \"auto\": [expr {$uasked ? {false} : {true}}]"
} else {
Expand Down
16 changes: 8 additions & 8 deletions doc/source/cookbook/log-module-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configuration that traces every call to a modulefile evaluation.
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:caption: siteconfig.tcl
:lines: 13-36
:lines: 13-41
:lineno-start: 13

This code defines a ``logModfileInterp`` procedure which is set to be
Expand All @@ -32,8 +32,8 @@ following line:

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

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
Expand All @@ -43,8 +43,8 @@ produced from thousands of computing nodes.

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

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 +53,8 @@ with `trace`_ Tcl command.
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
:language: tcl
:caption: siteconfig.tcl
:lines: 38-58
:lineno-start: 38
:lines: 43-63
:lineno-start: 43

.. note::

Expand Down Expand Up @@ -125,7 +125,7 @@ A log entry can then be retrieved from system log files:

.. parsed-literal::
:ps:`$` journalctl -q -t module -n 1
:ps:`$` journalctl -q -t module
Sep 12 20:24:01 hostname module[9925]: { "user": "username", "cmd": "ml", "args": "av" }
Sep 12 20:24:02 hostname module[9925]: { "user": "username", "mode": "load", "module": "foo/1.0", "auto": false }
Sep 12 20:24:02 hostname module[9925]: { "user": "username", "cmd": "ml", "args": "foo" }
Expand Down

0 comments on commit 9bff25c

Please sign in to comment.