Skip to content

Logging

Railtracks provides built-in logging to help track the execution of your flows. Logs are automatically generated and can be viewed in the terminal or saved to a file.

Example Logs
[+3.525  s] RT          : INFO     - START CREATED Github Agent
[+8.041  s] RT          : INFO     - Github Agent CREATED create_issue
[+8.685  s] RT          : INFO     - create_issue DONE
[+14.333 s] RT          : INFO     - Github Agent CREATED assign_copilot_to_issue
[+14.760 s] RT          : INFO     - assign_copilot_to_issue DONE
[+17.540 s] RT          : INFO     - Github Agent CREATED assign_copilot_to_issue
[+18.961 s] RT          : INFO     - assign_copilot_to_issue DONE
[+23.401 s] RT          : INFO     - Github Agent DONE

Critical

Every log sent by Railtracks will contain a parameter in extras for session_id which will be uuid tied to the session the error was thrown in.

Configuring Logging

Logging Levels

Railtracks supports six logging levels aligned with the standard Python logging framework:

  1. DEBUG: (Default for file logs) Includes all logs
  2. INFO: (Default) Includes INFO and above. Ideal for local development.
  3. WARNING: Includes WARNING and above. Recommended for production.
  4. ERROR: Includes recoverable issues that prevented part of the system from functioning correctly.
  5. CRITICAL: Includes severe failures that may cause shutdown.
  6. NONE: Disables all logging.
rt.set_config(logging_setting="DEBUG")
rt.set_config(logging_setting="INFO")
rt.set_config(logging_setting="CRITICAL")
rt.set_config(logging_setting="NONE")

Logging Handlers

Console Handler

By default, logs are printed to stdout and stderr.

File Handler

To save logs to a file, pass a log_file parameter to the config:

rt.set_config(log_file="my_logs.log")

File Handler logging level

Currently the logs outputted to the File Handler will be at DEBUG level for completeness. If you'd like us to support customizing this parameter, please open an issue at railtracks/issues

Custom Handlers

Railtracks uses the standard Python logging module with the RT prefix. You can attach custom handlers:

import logging


class CustomHandler(logging.Handler):
    def emit(self, record):
        # Custom logging logic
        pass


logger = logging.getLogger()
logger.addHandler(CustomHandler())

Example Usage

You can configure logging globally or per-run.

Global Configuration

rt.set_config(logging_setting="DEBUG", log_file="my_logs.log")
or you could set up your environment variables
RT_LOG_LEVEL = "DEBUG"
RT_LOG_FILE = "my_logs.log"
This will apply to all flows, unless a Session overwrites it. In that case it will change for the scope of that particular Session and return to the global setting afterwards.

Scoped Configuration

with rt.Session(logging_setting="DEBUG", log_file="my_logs.log") as runner:
    pass
Applies only within the context of the Session.


Forwarding Logs to External Services

You can forward logs to services like Loggly, Sentry, or Conductr by attaching custom handlers. Refer to each provider's documentation for integration details.

import railtownai

RAILTOWN_API_KEY = "YOUR_RAILTOWN_API_KEY"
railtownai.init(RAILTOWN_API_KEY)
import logging
from loggly.handlers import HTTPSHandler

LOGGLY_TOKEN = "YOUR_LOGGLY_TOKEN"
https_handler = HTTPSHandler(
    url=f"https://logs-01.loggly.com/inputs/{LOGGLY_TOKEN}/tag/python"
)
logger = logging.getLogger()
logger.addHandler(https_handler)
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    send_default_pii=True,  # Collects additional metadata
)

Log Message Examples

DEBUG Messages
Type Example
Runner Created RT.Runner : DEBUG - Runner <RUNNER_ID> is initialized
Node Created RT.Publisher: DEBUG - RequestCreation(current_node_id=<PARENT_NODE_ID>, new_request_id=<REQUEST_ID>, running_mode=async, new_node_type=<NODE_NAME>, args=<INPUT_ARGS>, kwargs=<INPUT_KWARGS>)
Node Completed RT.Publisher: DEBUG - <NODE_NAME> DONE with result <RESULT>
INFO Messages
Type Example
Initial Request RT : INFO - START CREATED <NODE_NAME>
Invoking Nodes RT : INFO - <PARENT_NODE_NAME> CREATED <CHILD_NODE_NAME>
Node Completed RT : INFO - <NODE_NAME> DONE
Run Data Saved RT.Runner : INFO - Saving execution info to .railtracks\<RUNNER_ID>.json
WARNING Messages
Type Example
Overwriting File RT.Runner : WARNING - File .railtracks\<RUNNER_ID>.json already exists, overwriting...
ERROR Messages
Type Example
Node Failed RT : ERROR - <NODE_NAME> FAILED