Skip to content

Commit 9bff25c

Browse files
committed
doc: fix log-module-command recipe siteconfig.tcl
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
1 parent fec3072 commit 9bff25c

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

.aspell.en.pws

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 797
1+
personal_ws-1.1 en 798
22
ABBRVLIST
33
ActiveTcl
44
Adrien
@@ -12,6 +12,7 @@ BASEPREFIX
1212
BEFH
1313
Booleans
1414
Bourne
15+
Burgue�o
1516
CEST
1617
CET
1718
CFLAGS

NEWS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ Modules 5.1.0 (not yet released)
226226
* When mentioning the loading, unloading or refreshing evaluation of a module,
227227
report the tags associated to this module as done when printing results of
228228
:subcmd:`list` sub-command.
229+
* Fix :ref:`log-module-command` cookbook recipe not to break Modules
230+
initialization when using provided :file:`siteconfig.tcl` file. (fix issue
231+
#453 with contribution from Eric Burgueño)
229232

230233
.. _Code of conduct: https://github.com/cea-hpc/modules/blob/master/CODE_OF_CONDUCT.md
231234
.. _codespell: https://github.com/codespell-project/codespell

doc/example/log-module-commands/siteconfig.tcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ proc logModfileInterp {cmdstring code result op} {
1414
# parse context
1515
lassign $cmdstring cmdname modfile modname
1616
set mode [currentState mode]
17+
if {[info level] > 1} {
18+
set caller [lindex [info level -1] 0]
19+
} else {
20+
set caller {}
21+
}
1722

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

2126
# add info on load mode to know if module is auto-loaded or not
22-
if {$mode eq {load}} {
27+
if {$mode eq {load} && $caller eq {cmdModuleLoad}} {
2328
upvar 1 uasked uasked
2429
set extra ", \"auto\": [expr {$uasked ? {false} : {true}}]"
2530
} else {

doc/source/cookbook/log-module-commands.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ configuration that traces every call to a modulefile evaluation.
1717
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
1818
:language: tcl
1919
:caption: siteconfig.tcl
20-
:lines: 13-36
20+
:lines: 13-41
2121
:lineno-start: 13
2222

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

3333
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
3434
:language: tcl
35-
:lines: 18-19
36-
:lineno-start: 18
35+
:lines: 23-24
36+
:lineno-start: 23
3737

3838
In the proposed code, the :command:`logger` command is run to generate a log
3939
message. Log entries are formatted as a JSON record which is convenient to
@@ -43,8 +43,8 @@ produced from thousands of computing nodes.
4343

4444
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
4545
:language: tcl
46-
:lines: 29-31
47-
:lineno-start: 29
46+
:lines: 34-36
47+
:lineno-start: 34
4848

4949
Example code also defines a ``logModuleCmd`` procedure which is set to be
5050
evaluated after each evaluation of the ``module`` and the ``ml`` procedures
@@ -53,8 +53,8 @@ with `trace`_ Tcl command.
5353
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
5454
:language: tcl
5555
:caption: siteconfig.tcl
56-
:lines: 38-58
57-
:lineno-start: 38
56+
:lines: 43-63
57+
:lineno-start: 43
5858

5959
.. note::
6060

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

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

0 commit comments

Comments
 (0)