Skip to content

Commit 52fda47

Browse files
committed
doc: fix logging sys on log-module-command recipe
Update log-module-command recipe to ensure the logging system is not broken by the current user environment. Fixes #475.
1 parent 470d922 commit 52fda47

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
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 852
1+
personal_ws-1.1 en 853
22
ABBRVLIST
33
ActiveTcl
44
Adrien
@@ -378,6 +378,7 @@ etcdir
378378
eu
379379
eval
380380
exe
381+
execLogger
381382
execcmdlist
382383
executables
383384
execve

NEWS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Modules 5.2.0 (not yet released)
141141
* Add :subcmd:`stashlist` sub-command to list all stash collection files.
142142
* Update :subcmd:`savelist` sub-command to filter out stash collections unless
143143
if :option:`--all` option is set.
144+
* Doc: ensure current user environment does not break logging system in
145+
:ref:`log-module-command` recipe. (fix issue #475)
144146

145147
.. _Nagelfar: http://nagelfar.sourceforge.net/
146148
.. _ShellCheck: https://www.shellcheck.net/

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
# installation. Refer to the "Modulecmd startup" section in the
1111
# module(1) man page to get this location.
1212

13+
proc execLogger {msg} {
14+
# ensure logger command is executed with system libs
15+
if {[info exists ::env(LD_LIBRARY_PATH)]} {
16+
set ORIG_LD_LIBRARY_PATH $::env(LD_LIBRARY_PATH)
17+
unset ::env(LD_LIBRARY_PATH)
18+
}
19+
exec logger -t module $msg
20+
# restore current user lib setup
21+
if {[info exists ORIG_LD_LIBRARY_PATH]} {
22+
set ::env(LD_LIBRARY_PATH) $ORIG_LD_LIBRARY_PATH
23+
}
24+
}
25+
1326
proc logModfileInterp {cmdstring code result op} {
1427
# parse context
1528
lassign $cmdstring cmdname modfile modname
@@ -32,8 +45,8 @@ proc logModfileInterp {cmdstring code result op} {
3245
}
3346

3447
# produced log entry (formatted as a JSON record)
35-
exec logger -t module "{ \"user\": \"[get-env USER]\", \"mode\":\
36-
\"$mode\", \"module\": \"$modname\"${extra} }"
48+
execLogger "{ \"user\": \"[get-env USER]\", \"mode\": \"$mode\",\
49+
\"module\": \"$modname\"${extra} }"
3750
}
3851
}
3952

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

5568
# produced log entry (formatted as a JSON record)
56-
exec logger -t module "{ \"user\": \"[get-env USER]\", \"cmd\":\
57-
\"$cmdname\", \"args\": \"$args\" }"
69+
execLogger "{ \"user\": \"[get-env USER]\", \"cmd\": \"$cmdname\",\
70+
\"args\": \"$args\" }"
5871
}
5972
}
6073

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ 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-41
21-
:lineno-start: 13
20+
:lines: 26-54
21+
:lineno-start: 26
2222

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

3333
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
3434
:language: tcl
35-
:lines: 23-24
36-
:lineno-start: 23
35+
:lines: 36-37
36+
:lineno-start: 36
37+
38+
In the proposed code, log entries are formatted as a JSON record which is
39+
convenient to push these logs in a search and analytics engine like
40+
`Elasticsearch`_ or `Splunk`_. Such tools help to globally monitor the whole
41+
set of log entries produced from thousands of computing nodes.
42+
43+
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
44+
:language: tcl
45+
:lines: 47-49
46+
:lineno-start: 47
3747

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

4453
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl
4554
:language: tcl
46-
:lines: 34-36
47-
:lineno-start: 34
55+
:lines: 13-24
56+
:lineno-start: 13
4857

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

5968
.. note::
6069

0 commit comments

Comments
 (0)