log-module-commands.rst (modules-5.1.1.tar.bz2) | : | log-module-commands.rst (modules-5.2.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
Implementation | Implementation | |||
-------------- | -------------- | |||
Logging module commands is implemented by the use of a site-specific | Logging module commands is implemented by the use of a site-specific | |||
configuration that traces every call to a modulefile evaluation. | configuration that traces every call to a modulefile evaluation. | |||
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | .. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | |||
:language: tcl | :language: tcl | |||
:caption: siteconfig.tcl | :caption: siteconfig.tcl | |||
:lines: 13-41 | :lines: 26-54 | |||
:lineno-start: 13 | :lineno-start: 26 | |||
This code defines a ``logModfileInterp`` procedure which is set to be | This code defines a ``logModfileInterp`` procedure which is set to be | |||
evaluated after each evaluation of the ``execute-modulefile`` procedure with | evaluated after each evaluation of the ``execute-modulefile`` procedure with | |||
the `trace`_ Tcl command. Thanks to the ``trace`` mechanism | the `trace`_ Tcl command. Thanks to the ``trace`` mechanism | |||
``logModfileInterp`` receives the arguments passed to ``execute-modulefile``. | ``logModfileInterp`` receives the arguments passed to ``execute-modulefile``. | |||
The ``logModfileInterp`` procedure applies filter to only log *load* and | The ``logModfileInterp`` procedure applies filter to only log *load* and | |||
*unload* modulefile evaluations. It may be extended to the other evaluation | *unload* modulefile evaluations. It may be extended to the other evaluation | |||
modes (*help*, *display*, *test*, *whatis* and *refresh*) by adapting the | modes (*help*, *display*, *test*, *whatis* and *refresh*) by adapting the | |||
following line: | following line: | |||
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | .. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | |||
:language: tcl | :language: tcl | |||
:lines: 23-24 | :lines: 36-37 | |||
:lineno-start: 23 | :lineno-start: 36 | |||
In the proposed code, the :command:`logger` command is run to generate a log | In the proposed code, log entries are formatted as a JSON record which is | |||
message. Log entries are formatted as a JSON record which is convenient to | convenient to push these logs in a search and analytics engine like | |||
push these logs in a search and analytics engine like `Elasticsearch`_ or | `Elasticsearch`_ or `Splunk`_. Such tools help to globally monitor the whole | |||
`Splunk`_. Such tools help to globally monitor the whole set of log entries | set of log entries produced from thousands of computing nodes. | |||
produced from thousands of computing nodes. | ||||
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | .. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | |||
:language: tcl | :language: tcl | |||
:lines: 34-36 | :lines: 47-49 | |||
:lineno-start: 34 | :lineno-start: 47 | |||
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: 13-24 | ||||
:lineno-start: 13 | ||||
Example code also defines a ``logModuleCmd`` procedure which is set to be | Example code also defines a ``logModuleCmd`` procedure which is set to be | |||
evaluated after each evaluation of the ``module`` and the ``ml`` procedures | evaluated after each evaluation of the ``module`` and the ``ml`` procedures | |||
with `trace`_ Tcl command. | with `trace`_ Tcl command. | |||
.. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | .. literalinclude:: ../../example/log-module-commands/siteconfig.tcl | |||
:language: tcl | :language: tcl | |||
:caption: siteconfig.tcl | :caption: siteconfig.tcl | |||
:lines: 43-63 | :lines: 56-76 | |||
:lineno-start: 43 | :lineno-start: 56 | |||
.. note:: | .. note:: | |||
This code example may be extended to log for instance additional | This code example may be extended to log for instance additional | |||
information in each message. The `upvar`_ Tcl command may be used to | information in each message. The `upvar`_ Tcl command may be used to | |||
retrieve variables from the calling context. However beware that the | retrieve variables from the calling context. However beware that the | |||
internal code of Modules may change, so if you rely on internal variables | internal code of Modules may change, so if you rely on internal variables | |||
please re-check the code in the :file:`siteconfig.tcl` file deployed after | please re-check the code in the :file:`siteconfig.tcl` file deployed after | |||
each upgrade of Modules. | each upgrade of Modules. | |||
**Compatible with Modules v4.2+** | **Compatible with Modules v4.2+** | |||
.. _trace: https://www.tcl.tk/man/tcl8.5/TclCmd/trace.html | .. _trace: https://www.tcl-lang.org/man/tcl8.5/TclCmd/trace.html | |||
.. _Elasticsearch: https://www.elastic.co/elasticsearch/ | .. _Elasticsearch: https://www.elastic.co/elasticsearch/ | |||
.. _Splunk: https://www.splunk.com/ | .. _Splunk: https://www.splunk.com/ | |||
.. _upvar: https://www.tcl.tk/man/tcl8.5/TclCmd/upvar.html | .. _upvar: https://www.tcl-lang.org/man/tcl8.5/TclCmd/upvar.html | |||
Installation | Installation | |||
------------ | ------------ | |||
Create site-specific configuration directory if it does not exist yet: | Create site-specific configuration directory if it does not exist yet: | |||
.. parsed-literal:: | .. parsed-literal:: | |||
$ mkdir \ |etcdir| | $ mkdir \ |etcdir| | |||
skipping to change at line 139 | skipping to change at line 148 | |||
Sep 12 20:24:01 hostname module[9925]: { "user": "username", "cmd": "ml", "a rgs": "av" } | Sep 12 20:24:01 hostname module[9925]: { "user": "username", "cmd": "ml", "a rgs": "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", "mode": "load", "module": "foo/1.0", "auto": false } | |||
Sep 12 20:24:02 hostname module[9925]: { "user": "username", "cmd": "ml", "a rgs": "foo" } | Sep 12 20:24:02 hostname module[9925]: { "user": "username", "cmd": "ml", "a rgs": "foo" } | |||
Sep 12 20:24:03 hostname module[9925]: { "user": "username", "mode": "load", "module": "qux/1.0", "auto": true } | Sep 12 20:24:03 hostname module[9925]: { "user": "username", "mode": "load", "module": "qux/1.0", "auto": true } | |||
Sep 12 20:24:03 hostname module[9925]: { "user": "username", "mode": "load", "module": "bar/1.0", "auto": false } | Sep 12 20:24:03 hostname module[9925]: { "user": "username", "mode": "load", "module": "bar/1.0", "auto": false } | |||
Sep 12 20:24:03 hostname module[9925]: { "user": "username", "cmd": "module" , "args": "load bar" } | Sep 12 20:24:03 hostname module[9925]: { "user": "username", "cmd": "module" , "args": "load bar" } | |||
Sep 12 20:24:04 hostname module[9925]: { "user": "username", "mode": "unload ", "module": "bar/1.0" } | Sep 12 20:24:04 hostname module[9925]: { "user": "username", "mode": "unload ", "module": "bar/1.0" } | |||
Sep 12 20:24:04 hostname module[9925]: { "user": "username", "mode": "unload ", "module": "qux/1.0" } | Sep 12 20:24:04 hostname module[9925]: { "user": "username", "mode": "unload ", "module": "qux/1.0" } | |||
Sep 12 20:24:04 hostname module[9925]: { "user": "username", "mode": "unload ", "module": "foo/1.0" } | Sep 12 20:24:04 hostname module[9925]: { "user": "username", "mode": "unload ", "module": "foo/1.0" } | |||
Sep 12 20:24:04 hostname module[9925]: { "user": "username", "cmd": "module" , "args": "purge" } | Sep 12 20:24:04 hostname module[9925]: { "user": "username", "cmd": "module" , "args": "purge" } | |||
.. vim:set tabstop=2 shiftwidth=2 expandtab autoindent: | ||||
End of changes. 8 change blocks. | ||||
15 lines changed or deleted | 24 lines changed or added |