Logger
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 focus on plugin-related system runtime logs.
The following explains how to create and print logs during plugin development.
Default Printing Methods
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. The module, submodule, and method fields will be extracted as separate fields, and the remaining fields will be placed in the meta field.
Output to Other Files
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.
Custom Logger
If you don't want to use the system-provided printing methods and prefer to use Winston's native approach directly, you can create logs using the following methods.
createLogger
options 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.createLogger
In multi-app scenarios, if you want custom logs to be output to a directory named after the current application, you can use this method.
plugin.createLogger
The use case and method are the same as app.createLogger.
Related Links
- Context - Print logs via
ctx.loggerin middleware and Actions - Plugin - Use logging via
this.logandplugin.createLoggerin plugins - Telemetry - Combine logging with telemetry for observability
- Middleware - Typical scenarios for logging requests in middleware
- Server Development Overview - Where the logging system fits in the server architecture

