docs/Management/Development and Configuration/Datapack/Logging.md
ehrumsey d42f523a83 vault backup: 2025-03-28 11:01:29
Affected files:
.obsidian/workspace.json
Management/Development and Configuration/Datapack/Logging.md
2025-03-28 11:01:29 -05:00

48 lines
2.2 KiB
Markdown

---
title: Logging
draft: "false"
---
# Usage
## Log Levels
This module has 5 log levels:
- `FATAL`: (5) Indicates that at least an entire module will need to shut down. Generally indicates the likelihood of data corruption.
- `ERROR`: (4) The requested operation could not be completed, or some other problem that prevents necessary or requested functions from working as intended.
- `WARNING`: (3) Something has or may have gone wrong, but nothing has been prevented from functioning. Warnings should be investigated, but do not require immediate action.
- `INFO`: (2) Informational log ("Did this thing", "Started this process"). Shouldn't be too detailed.
- `DEBUG`: (1) Granular play-by-play useful for troubleshooting errors. More likely to include detailed `body`.
By default, only levels 3 and up will be output. Debug logging, which displays all levels, can be manually toggled in-game with `function ferdinland:logger/toggle`.
Each log level has an associated test function which will output:
```
[<LOG_LEVEL>]: (logger) This is a test
```
The functions are:
- `ferdinland:logger/test_fatal`
- `ferdinland:logger/test_error`
- `ferdinland:logger/test_warning`
- `ferdinland:logger/test_info`
- `ferdinland:logger/test_debug`
## Syntax
The module uses the following syntax:
```ts
logger(type, caller, message, body)
```
`type` takes an integer from `1` to `5`, corresponding to the associated log level.
`caller` takes an unquoted string. This should reflect the function triggering the log message: `module.path.to.function`.
`message` takes a quoted string or an NBT storage location. NBT storage should be in standard JMC format (`::path.to.element`). *Only* paths beginning with `::` with be processed as storages. `@e[tag=entity]::path.to.element` will be processed as a string.
The content of `message` will be output in a `say` command, and will be visible in the server console.
`body` takes a `tellraw` object. It will be output in the command `tellraw @ <body>`.
# Configuring
The log level is set to `3` by default. This can be changed manually in game with the command where `<int>` is replaced with the desired log level:
```vb
scoreboard players set $log_level __variable__ <int>
```