📄 Log#
#bs.log:_
👶 First steps#
Bookshelf proposes facilities to log messages in the chat. There are different logs levels to use according to the type of log:
Debug
Information
Warning
Error
- Manage the log granularity
A lot of logs in their code can flood the chat. To avoid that, the log module of Bookshelf can be configure to display only specific logs according to two parameters: the log level and the feature. To do that, the user wishing to display these specific logs need to give themselves tags with the following syntax:
bs.log.<module>.<feature>.<level>
where level is amongdebug
,info
,warn
anderror
.Each log level enables the visualisation of the next levels. For instance, if a user give themselves a tag finishing by
warn
, they can visualize logs ofwarn
anderror
levels.The tags
bs.log._.<level>
enables the display of all logs regardless of the feature. The tagsbs.log.<module>.<feature>._
enables the display of all logs regardless of the level (equivalent tobs.log.<module>.<feature>.debug
). The tagbs.log._._
enables the display of all logs.By default, the logs are not displayed to any user.
- Customize the log message
The log functions take three variables as input:
The
path
(type: string) of the current function. This variable follows the minecraft path format.The logged
feature
(type: string). This variable is used in the tag and follows the following syntax:<module without 'bs.'>.<feature>
.The log content
message
(type: string). This variable is any valid JSON text component usable in a tellraw. Several JSON text components can be specified by joining them with a comma,
. Note: To specify a plain string text as message, the message needs to have escaped quotes. For instance:"\"message\""
or'"message"'
.
- Examples
The following function called
bs.foo:bar
:function #bs.log:warn { path: "bs.foo:bar", feature: "foo.bar", message: '"A warning message"' }
Will display the following message if the user has one of these tags
bs.log.foo.bar.warn
,bs.log.foo.bar.info
,bs.log.foo.bar.debug
,bs.log._.warn
,bs.log._.info
,bs.log._.debug
,bs.log._._
,bs.log.foo.bar._
:The following function called
bs.foo:baz
:function #bs.log:info { path: "bs.foo:baz", feature: "foo.baz", message: '{"text": "Score: ","color": "light_purple"}, {"score": {"name": "@p", "objective": "bs.in.0"}}, {"text": ", "},{"text": "@p: ", "color": "light_purple"}, {"selector": "@p"}, {"text": ", hoverevent", "hoverEvent": {"action": "show_text", "contents": "Hi!"}}' }
Will display the following message if the user has one of these tags
bs.log.foo.baz.info
,bs.log.foo.baz.debug
,bs.log._.info
,bs.log._.debug
,bs.log.foo.baz._
:
🔧 Functions#
You can find below all the function available in this module.
Debug#
#bs.log:debug
Allows to log a message as a debug message.
- Inputs
- (macro variable)
path
: string The Minecraft path of the current function.
- (macro variable)
feature
: string The logged feature. Format:
<module>:<feature name>
. Used in the tag as described in the Customize log message section.- (macro variable)
message
: string The log message. Format: valid JSON text component as described in Manage the log granularity section.
- (macro variable)
- Examples
Example with a simple raw text:
function #bs.log:debug { path: "bs.foo:bar", feature: "foo.bar", message: '"A warning message"' }
Example with a complex JSON text components:
function #bs.log:debug { path: "bs.foo:baz", feature: "foo.baz", message: '{"text": "Score: ","color": "light_purple"}, {"score": {"name": "@p", "objective": "bs.in.0"}}, {"text": ", "},{"text": "@p: ", "color": "light_purple"}, {"selector": "@p"}, {"text": ", hoverevent", "hoverEvent": {"action": "show_text", "contents": "Hi!"}}' }
Credits: theogiraudet
Information#
#bs.log:info
Allows to log a message as an information message.
- Inputs
- (macro variable)
path
: string The Minecraft path of the current function.
- (macro variable)
feature
: string The logged feature. Format:
<module>:<feature name>
. Used in the tag as described in the Customize log message section.- (macro variable)
message
: string The log message. Format: valid JSON text component as described in Manage the log granularity section.
- (macro variable)
- Examples
Example with a simple raw text:
function #bs.log:info { path: "bs.foo:bar", feature: "foo.bar", message: '"A warning message"' }
Example with a complex JSON text components:
function #bs.log:info { path: "bs.foo:baz", feature: "foo.baz", message: '{"text": "Score: ","color": "light_purple"}, {"score": {"name": "@p", "objective": "bs.in.0"}}, {"text": ", "},{"text": "@p: ", "color": "light_purple"}, {"selector": "@p"}, {"text": ", hoverevent", "hoverEvent": {"action": "show_text", "contents": "Hi!"}}' }
Credits: theogiraudet
Warning#
#bs.log:warn
Allows to log a message as a warning message.
- Inputs
- (macro variable)
path
: string The Minecraft path of the current function.
- (macro variable)
feature
: string The logged feature. Format:
<module>:<feature name>
. Used in the tag as described in the Customize log message section.- (macro variable)
message
: string The log message. Format: valid JSON text component as described in Manage the log granularity section.
- (macro variable)
- Examples
Example with a simple raw text:
function #bs.log:warn { path: "bs.foo:bar", feature: "foo.bar", message: '"A warning message"' }
Example with a complex JSON text components:
function #bs.log:warn { path: "bs.foo:baz", feature: "foo.baz", message: '{"text": "Score: ","color": "light_purple"}, {"score": {"name": "@p", "objective": "bs.in.0"}}, {"text": ", "},{"text": "@p: ", "color": "light_purple"}, {"selector": "@p"}, {"text": ", hoverevent", "hoverEvent": {"action": "show_text", "contents": "Hi!"}}' }
Credits: theogiraudet
Error#
#bs.log:error
Allows to log a message as an error message.
- Inputs
- (macro variable)
path
: string The Minecraft path of the current function.
- (macro variable)
feature
: string The logged feature. Format:
<module>:<feature name>
. Used in the tag as described in the Customize log message section.- (macro variable)
message
: string The log message. Format: valid JSON text component as described in Manage the log granularity section.
- (macro variable)
- Examples
Example with a simple raw text:
function #bs.log:error { path: "bs.foo:bar", feature: "foo.bar", message: '"A warning message"' }
Example with a complex JSON text components:
function #bs.log:error { path: "bs.foo:baz", feature: "foo.baz", message: '{"text": "Score: ","color": "light_purple"}, {"score": {"name": "@p", "objective": "bs.in.0"}}, {"text": ", "},{"text": "@p: ", "color": "light_purple"}, {"selector": "@p"}, {"text": ", hoverevent", "hoverEvent": {"action": "show_text", "contents": "Hi!"}}' }
Credits: theogiraudet
💬 Did it help you?
Feel free to leave your questions and feedbacks below!