logologo
Get Started
Tutorials
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Get Started
Tutorials
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Importing Modules
Rendering in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.location
Next Pagectx.makeResource()

#ctx.logger

A logging wrapper based on pino, providing high-performance structured JSON logs. It is recommended to use ctx.logger instead of console for easier log collection and analysis.

#Scenarios

ctx.logger can be used in all RunJS scenarios for debugging, error tracking, performance analysis, etc.

#Type Definition

logger: pino.Logger;

ctx.logger is an instance of engine.logger.child({ module: 'flow-engine' }), which is a pino child logger with a module context.

#Log Levels

pino supports the following levels (from highest to lowest):

LevelMethodDescription
fatalctx.logger.fatal()Fatal error, usually leading to process exit
errorctx.logger.error()Error, indicating a failed request or operation
warnctx.logger.warn()Warning, indicating potential risks or abnormal situations
infoctx.logger.info()General runtime information
debugctx.logger.debug()Debugging information, used during development
tracectx.logger.trace()Detailed trace, used for deep diagnostics

#Recommended Usage

The recommended format is level(msg, meta): the message comes first, followed by an optional metadata object.

ctx.logger.info('Block loading complete');
ctx.logger.info('Operation successful', { recordId: 456 });
ctx.logger.warn('Performance warning', { duration: 5000 });
ctx.logger.error('Operation failed', { userId: 123, action: 'create' });
ctx.logger.error('Request failed', { err });

pino also supports level(meta, msg) (object first) or level({ msg, ...meta }) (single object), which can be used as needed.

#Examples

#Basic Usage

ctx.logger.info('Block loading complete');
ctx.logger.warn('Request failed, using cache', { err });
ctx.logger.debug('Saving...', { recordId: ctx.record?.id });

#Creating a Child Logger with child()

// Create a child logger with context for the current logic
const log = ctx.logger.child({ scope: 'myBlock' });
log.info('Executing step 1');
log.debug('Executing step 2', { step: 2 });

#Relationship with console

It is recommended to use ctx.logger directly to obtain structured JSON logs. If you are accustomed to using console, the mappings are: console.log → ctx.logger.info, console.error → ctx.logger.error, console.warn → ctx.logger.warn.

#Log Format

pino outputs structured JSON, where each log entry contains:

  • level: Log level (numeric)
  • time: Timestamp (milliseconds)
  • msg: Log message
  • module: Fixed as flow-engine
  • Other custom fields (passed via objects)

#Notes

  • Logs are structured JSON, making them easy to collect, search, and analyze.
  • Child loggers created via child() also follow the level(msg, meta) recommendation.
  • Some runtime environments (such as Workflows) may use different log output methods.

#Related

  • pino — The underlying logging library