NocoBase logging is based on Winston. By default, NocoBase divides logs into API request logs, system runtime logs, and SQL execution logs. API request logs and SQL execution logs are printed internally by the application. Plugin developers usually only need to print plugin-related system runtime logs.
This document explains how to create and print logs during plugin development.
NocoBase provides system runtime log printing methods. Logs are printed according to specified fields and output to specified files.
All of the above methods follow the usage below:
The first parameter is the log message, and the second parameter is an optional metadata object, which can be any key-value pairs. where module, submodule, and method will be extracted as separate fields, and the remaining fields will be placed in the meta field.
If you want to use the system default printing method but don't want to output to the default file, you can create a custom system logger instance using createSystemLogger.
If you want to use Winston's native methods instead of the system-provided ones, you can create logs using the following methods.
createLoggeroptions extends the original winston.LoggerOptions.
transports - Use 'console' | 'file' | 'dailyRotateFile' to apply preset output methods.format - Use 'logfmt' | 'json' | 'delimiter' to apply preset printing formats.app.createLoggerIn multi-app scenarios, sometimes we want custom output directories and files, which can be output to a directory named after the current application.
plugin.createLoggerThe use case and method are the same as app.createLogger.