log.setLevel: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by 4 users not shown)
Line 8: Line 8:
<br>The log file will be found in your user directory under {{code|.maptool-rptools/logs}}.
<br>The log file will be found in your user directory under {{code|.maptool-rptools/logs}}.
|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
log.setLevel(logger, loglevel)
log.setLevel(logger, loglevel)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
{{param|logger|String containing a logger name.}}
{{param|logger|String containing a logger name.}}
{{param|loglevel|String containing a log level: DEBUG,INFO,WARN,ERROR,FATAL}}
{{param|loglevel|String containing a log level: DEBUG,INFO,WARN,ERROR,FATAL}}


The default level for all loggers is ERROR which means that only messages at ERROR or FATAL log level will be output.  The levels noted above are in verbosity order from most(DEBUG) to least(FATAL).
The default level for all loggers is INFO, which means that messages at INFO, WARN, ERROR and FATAL log level will be output.  The levels noted above are in verbosity order from most(DEBUG) to least(FATAL).


|example=
|example=
Set the logging level for the MapToolLineParser to '''WARN'''.
Set the logging level for the MapToolLineParser to '''WARN'''.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: log.setLevel("net.rptools.maptool.client.MapToolLineParser","WARN")]
[r: log.setLevel("net.rptools.maptool.client.MapToolLineParser","WARN")]
</source>
</syntaxhighlight>
'''Returns:'''
'''Returns:'''
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
WARN
WARN
</source>
</syntaxhighlight>


Get a list of loggers and then, using {{func|input}}, select a logging level for it.
Get a list of loggers and then, using {{func|input}}, select a logging level for it.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: loggers = json.sort(log.getLoggers(),"a","name")]
[h: loggers = json.sort(log.getLoggers(),"a","name")]
[h: loggerList = ""]
[h: loggerList = ""]
Line 41: Line 41:
[r: "Setting <i><b>" + lname + "</b></i> to <b>" + level + "</b>."]
[r: "Setting <i><b>" + lname + "</b></i> to <b>" + level + "</b>."]
[h: log.setLevel(lname,level)]
[h: log.setLevel(lname,level)]
</syntaxhighlight>
<br/>
[[File:SelectLoggerLevel.png]]


|also=
|also=
[[log.getLoggers|log.getLoggers]]
{{func|log.getLoggers}}  &nbsp;[[Available Loggers]]
</source>
[[File:SelectLoggerLevel.png]]
}}
}}
[[Category:Log Function]]
[[Category:Log Function]]

Latest revision as of 23:59, 15 March 2023

log.setLevel() Function

 Note: This function can only be used in a Trusted Macro

Introduced in version 1.5.2
Set the logging level for the specified logger.
The log file will be found in your user directory under .maptool-rptools/logs.

Usage

log.setLevel(logger, loglevel)

Parameters

  • logger - String containing a logger name.
  • loglevel - String containing a log level: DEBUG,INFO,WARN,ERROR,FATAL

The default level for all loggers is INFO, which means that messages at INFO, WARN, ERROR and FATAL log level will be output. The levels noted above are in verbosity order from most(DEBUG) to least(FATAL).

Example

Set the logging level for the MapToolLineParser to WARN.
[r: log.setLevel("net.rptools.maptool.client.MapToolLineParser","WARN")]

Returns:

WARN

Get a list of loggers and then, using input(), select a logging level for it.

[h: loggers = json.sort(log.getLoggers(),"a","name")]
[h: loggerList = ""]
[h, FOREACH(logger, loggers), CODE: {
    [h: loggerList = listAppend(loggerList,json.get(logger,"name"))]
}]
[h:status=input(
    "junkVar|Select a Logger and Level||LABEL|SPAN=TRUE",
    "lname|"+loggerList+"|Logger|LIST|VALUE=STRING",
    "level|DEBUG,INFO,WARN,ERROR,FATAL|Level|LIST|VALUE=STRING")]
[h:abort(status)]
[r: "Setting <i><b>" + lname + "</b></i> to <b>" + level + "</b>."]
[h: log.setLevel(lname,level)]


See Also