Loggers

Built-in loggers

dagster.loggers.colored_console_logger(*args, **kwargs)

Core class for defining loggers.

Loggers are job-scoped logging handlers, which will be automatically invoked whenever dagster messages are logged from within a job.

Parameters
  • logger_fn (Callable[[InitLoggerContext], logging.Logger]) – User-provided function to instantiate the logger. This logger will be automatically invoked whenever the methods on context.log are called from within job/pipeline compute logic.

  • config_schema (Optional[ConfigSchema]) – The schema for the config. Configuration data available in init_context.logger_config. If not set, Dagster will accept any config provided.

  • description (Optional[str]) – A human-readable description of this logger.

dagster.loggers.json_console_logger(*args, **kwargs)

Core class for defining loggers.

Loggers are job-scoped logging handlers, which will be automatically invoked whenever dagster messages are logged from within a job.

Parameters
  • logger_fn (Callable[[InitLoggerContext], logging.Logger]) – User-provided function to instantiate the logger. This logger will be automatically invoked whenever the methods on context.log are called from within job/pipeline compute logic.

  • config_schema (Optional[ConfigSchema]) – The schema for the config. Configuration data available in init_context.logger_config. If not set, Dagster will accept any config provided.

  • description (Optional[str]) – A human-readable description of this logger.

Logging from an @op

class dagster.DagsterLogManager(dagster_handler, level=0, managed_loggers=None)[source]

Centralized dispatch for logging from user code.

Handles the construction of uniform structured log messages and passes them through to the underlying loggers/handlers.

An instance of the log manager is made available to ops as context.log. Users should not initialize instances of the log manager directly. To configure custom loggers, set the logger_defs argument in an @job decorator or when calling the to_job() method on a GraphDefinition.

The log manager inherits standard convenience methods like those exposed by the Python standard library logging module (i.e., within the body of an op, context.log.{debug, info, warning, warn, error, critical, fatal}).

The underlying integer API can also be called directly using, e.g. context.log.log(5, msg), and the log manager will delegate to the log method defined on each of the loggers it manages.

User-defined custom log levels are not supported, and calls to, e.g., context.log.trace or context.log.notice will result in hard exceptions at runtime.

Defining custom loggers

@dagster.logger(config_schema=None, description=None)[source]

Define a logger.

The decorated function should accept an InitLoggerContext and return an instance of logging.Logger. This function will become the logger_fn of an underlying LoggerDefinition.

Parameters
  • config_schema (Optional[ConfigSchema]) – The schema for the config. Configuration data available in init_context.logger_config. If not set, Dagster will accept any config provided.

  • description (Optional[str]) – A human-readable description of the logger.

class dagster.LoggerDefinition(logger_fn, config_schema=None, description=None)[source]

Core class for defining loggers.

Loggers are job-scoped logging handlers, which will be automatically invoked whenever dagster messages are logged from within a job.

Parameters
  • logger_fn (Callable[[InitLoggerContext], logging.Logger]) – User-provided function to instantiate the logger. This logger will be automatically invoked whenever the methods on context.log are called from within job/pipeline compute logic.

  • config_schema (Optional[ConfigSchema]) – The schema for the config. Configuration data available in init_context.logger_config. If not set, Dagster will accept any config provided.

  • description (Optional[str]) – A human-readable description of this logger.

configured(config_or_config_fn, config_schema=None, description=None)

Wraps this object in an object of the same type that provides configuration to the inner object.

Parameters
  • config_or_config_fn (Union[Any, Callable[[Any], Any]]) – Either (1) Run configuration that fully satisfies this object’s config schema or (2) A function that accepts run configuration and returns run configuration that fully satisfies this object’s config schema. In the latter case, config_schema must be specified. When passing a function, it’s easiest to use configured().

  • config_schema (ConfigSchema) – If config_or_config_fn is a function, the config schema that its input must satisfy.

  • description (Optional[str]) – Description of the new definition. If not specified, inherits the description of the definition being configured.

Returns (ConfigurableDefinition): A configured version of this object.

class dagster.InitLoggerContext(logger_config, logger_def=None, pipeline_def=None, run_id=None)[source]

Logger-specific initialization context.

An instance of this class is made available as the first argument to the logger_fn decorated by @logger or set on a LoggerDefinition.

Users should not instantiate this class.

logger_config

The configuration data provided by the run config. The schema for this data is defined by config_schema on the LoggerDefinition

Type

Any

pipeline_def

The pipeline/job definition currently being executed.

Type

Optional[PipelineDefinition]

logger_def

The logger definition for the logger being constructed.

Type

Optional[LoggerDefinition]

run_id

The ID for this run of the pipeline.

Type

str

dagster.build_init_logger_context(logger_config=None, pipeline_def=None, job_def=None)[source]

Builds logger initialization context from provided parameters.

This function can be used to provide the context argument to the invocation of a logger definition.

Note that you may only specify one of pipeline_def and job_def.

Parameters
  • logger_config (Any) – The config to provide during initialization of logger.

  • pipeline_def (Optional[PipelineDefinition]) – The pipeline definition that the logger will be used with.

  • job_def (Optional[JobDefinition]) – The job definition that the logger will be used with.

Examples

context = build_init_logger_context()
logger_to_init(context)