Logger
NocoBase provides a high-performance logging system based on pino. Anywhere you have access to context, you can get a logger instance through ctx.logger to record key logs during plugin or system runtime.
Basic Usage
These methods correspond to different log levels (from high to low):
Log Format
Each log output is in structured JSON format, containing the following fields by default:
Example output:
Context Binding
ctx.logger automatically injects context information, such as the current plugin, module, or request source, making logs more accurately traceable to their source.
Example output (with context):
Custom Logger
You can create custom logger instances in plugins, inheriting or extending default configurations:
Child loggers inherit the main logger's configuration and automatically attach context.
Log Level Hierarchy
Pino's log levels follow a numeric definition from high to low, where smaller numbers indicate lower priority.
Below is the complete log level hierarchy:
Pino only outputs logs greater than or equal to the current level configuration. For example, when the log level is info, debug and trace logs will be ignored.
Best Practices in Plugin Development
-
Use the Context Logger
Usectx.loggerin plugin, model, or application contexts to automatically carry source information. -
Distinguish Log Levels
- Use
errorto record business exceptions - Use
infoto record status changes - Use
debugto record development debugging information
- Use
-
Avoid Excessive Logging
Especially atdebugandtracelevels, it's recommended to only enable them in development environments. -
Use Structured Data
Pass object parameters instead of concatenating strings, which helps with log analysis and filtering.
By following these practices, developers can more efficiently track plugin execution, troubleshoot issues, and maintain a structured and extensible logging system.

