ns_log - Global server error log
The running NaviServer process opens a single log file into which all Notice, Error etc. messages are logged, whether originating from the server itself or form Tcl scripts and ADP pages.
The built-in set of severity levels can be extended. Logging can be enabled/disabled at run-time per-severity level. Custom filters can be added to process log messages.
Queue a message for the error log file if the given severity-level is enabled. The message arguments are concatenated with connecting spaces. The message will reach the log file when the per-thread cache is flushed.
The following are the predefined values of severity-level.
Something interesting occurred.
Something that could mean something bad occurred.
Something bad occurred.
Something extremely bad occurred. The server will shut down after logging this message.
Something occurred that implies that there is a bug in the code.
If debug level logging is enabled the the message is logged.
If dev level logging is enabled the message is logged.
Returns a count of buffered messages for the current thread. The message buffering can be turned on subcommand hold.
Return all buffered log messages, removing them from the buffer without writing them to the log file. Write buffered log messages from the current thread to the log file. Do not disable buffering enabled by hold.
Buffer log messages originating in the current thread indefinitely. Log messages are no longer written directly to the server log. Use the subcommand release to disable buffering.
Return a copy of any buffered log messages for the current thread.
Write buffered log messages from the current thread to the log file and disable buffering. Future log messages will not be buffered.
Return a list of available severity-levels. This includes the 7 predefined levels and those created with ns_logctl or via C code.
Return true if the given severity-level is enabled, false if it is disabled. If bool is given it enables/disables the given severity-level for all future log messages, server-wide.
If severity-level does not already exist and bool is given, then the new severity is created, enabled or disabled according to bool. Future calls to ns_log may use new severity-level.
Return statistics from calls to ns_log by severity-level.
Discard this threads buffered messages, leaving count untouched.
Register a log filter script with the given script-args where script should have the signature: script severity timestamp message ?script-args ...?. A handle will be returned which can be used to unregister the filter script.
Unregister the previously registered log filter script identified by handle.
Roll the server error log. This works whether the configuration parameter logroll is enabled or not. See ns_rollfile for details of log rolling.
The error log is configured globally for the whole server process.
ns_section "ns/parameters" ns_param ...
The following are valid configuration parameters:
Path to error log file. If the path is not fully qualified it is assumed to be relative to the server home directory ([ns_info home]). All the components of the path must exist. The server will fail to start if the log file cannot be opened. Default: logs/nsd.log
If true, messages of severity-level Notice are enabled. Default: true.
If true, messages of severity-level Dev are enabled. Default: false.
If true messages of severity-level Debug are enabled. Default: false.
If true, log entries will have timestamps with microsecond resolution. Default: false.
If true, an extra newline is added to each log entry. Default: false.
If true, the log file will be rolled when the server receives a SIGHUP signal. Default: true.
The number of old error log files to keep around if log rolling is enabled. Default: 10.
Equivalent log messages.
% ns_log notice "Hello World!" [21/May/1974:15:30:00][12257.40348b90][-command-] Notice: Hello World! % ns_log notice Hello World! [21/May/1974:15:30:01][12257.40348b90][-command-] Notice: Hello World!
Enable debug logging while the server is running.
nscp:1> ns_log debug testing... nscp:2> ns_logctl severity debug 0 nscp:3> ns_logctl severity debug true 1 nscp:4> ns_log debug testing... [01/April/1984:11:11:59][12257.40348b90][-nscp:1-] testing...
Report log messages at the end of an ADP page, as well as log them to the error log file.
<h1>An ADP Page</h1> <% ns_logctl hold # ... do some stuff here ... %> ... <% if {[ns_logctl count] > 0} { ns_adp_append "Log messages:" ns_adp_append "<pre>[ns_logctl peek]</pre>" } ns_logctl release %>
Create a new severity-level.
nscp:1> ns_logctl severities Notice Warning Error Fatal Bug Debug Dev nscp:2> ns_log my:debug "a debug message" unknown severity: "my:debug": should be one of: Notice Warning Error Fatal Bug Debug Dev nscp:3> ns_logctl severity my:debug off 0 nscp:4> ns_log my:debug "a debug message" nscp:5> ns_logctl severity my:debug on 0 nscp:6> ns_log my:debug "a debug message" [22/Nov/1963:13:25:00][1899.40349b90][-nscp:1-] my:debug: a debug message
ns_accesslog, ns_info, ns_rollfile