logger/README.md

39 lines
2.2 KiB
Markdown
Raw Normal View History

2022-11-06 16:21:10 +01:00
# Navy's logger
Simple logger I wrote to have a unified system for logging throughout my projects.
## TODO
- Discord webhook, need to write a separate package for that, don't want to add the entirety of d.js as a dep just for a webhook
## Features
Split into Master and Client for logging between processes, where master resides on the master process and the clients on the spawned processes.
2022-11-07 12:49:01 +01:00
Should be fairly trivial to modify it to work across nodes with websockets.
2022-11-08 21:57:03 +01:00
**Note**
When logging from a child process, the master logger expects the child process to be be in a wrapper containing at the very least an ID property to work properly (used for identifying which child the message came from).
Notably the logger will work with just a raw child process object though, it will lack the identifier.
The child processes are expected to be attached with the attach() method found in the master logger. This will attatch a listener for the 'message' event.
2022-11-07 12:49:01 +01:00
## Logger Options
```
{
2023-03-23 17:50:49 +01:00
//////// SHARED BETWEEN CLIENT & MASTER
guard: '_logger', // Message guard, e.g this property has to be true in the IPC message for the logger to read it
loglevel: false, // On the master logger this determines whether the output is written to console (i.e. will always be written to file), on the client this determines whether it is sent to the master at all
2022-11-07 12:49:01 +01:00
customTypes: [], // Log types, defaults are 'error', 'warn', 'info', 'debug', 'status'. Each one of these has an associated shorthand function, the custom ones will receive one too, e.g. adding 'access' to the custom types will add a logger.access() function
2023-03-23 17:50:49 +01:00
/////// MASTER EXCLUSIVE
2022-11-07 12:49:01 +01:00
customStreams: [], // File streams, by default there are streams for error and default
customTypeMapping: {}, // This maps a type to a stream, e.g. adding "warn": "error" will pipe any warnings to the error log file
customColors: {}, // Supports any colours chalk.js supports, e.g. "warn": "green" will turn warning outputs green
2023-03-23 17:50:49 +01:00
fileRotationFreq: 1, // How frequently to roate files in days - will not work with anything less than 1 day currently
directory: './logs', // Directory in which to write log files
2022-11-07 12:49:01 +01:00
}
```
**Log levels**
0 - Debug
1 - Info
2 - Status
3 - Warning
4 - Error