Robocorp Log

3.1.2 · active · verified Thu Apr 16

Robocorp Log provides automatic trace logging capabilities for Python applications, primarily used within the Robocorp automation ecosystem. It automatically captures function calls, arguments, return values, and exceptions, generating structured log data for debugging and analysis. The current version is 3.1.2. It is part of the broader Robocorp framework, with releases often aligned with other components of the Robocorp ecosystem rather than having a standalone, independent cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to manually set up `robocorp-log` to capture execution traces of Python functions. It configures a temporary directory for log output and explicitly calls `setup_auto_logging()` to enable the automatic instrumentation. Run this script, then inspect the generated files (e.g., `.robocorp_log`, `log.html`) in the `temp_robocorp_log_output` directory.

import os
from robocorp.log import setup_auto_logging, add_log_output
from pathlib import Path
import shutil

# Define a directory for log output
log_output_dir = Path("temp_robocorp_log_output")

# Ensure the log directory is clean before starting
if log_output_dir.exists():
    shutil.rmtree(log_output_dir)
log_output_dir.mkdir(parents=True, exist_ok=True)

# Add the log output target. This is crucial for logs to be written to a file.
add_log_output(log_output_dir)

# Manually set up auto-logging.
# In a Robocorp-managed run (e.g., Robocorp Lab/Assistant), this is often automatic.
setup_auto_logging()

def process_data(value: str, count: int):
    """A sample function to demonstrate automatic logging."""
    print(f"Processing value: {value} for {count} times")
    intermediate_result = f"Transformed_{value}"
    final_result = f"{intermediate_result}_{count}"
    if count > 1:
        print("Simulating a loop...")
        for i in range(count):
            print(f"  Iteration {i+1}")
    return final_result

if __name__ == "__main__":
    # Use environment variable for example input, common in automation
    input_value = os.environ.get('ROBOCORP_LOG_TEST_VALUE', 'sample_item')
    input_count = int(os.environ.get('ROBOCORP_LOG_TEST_COUNT', '1'))
    
    print(f"Starting demonstration with value='{input_value}', count={input_count}")
    result = process_data(input_value, input_count)
    print(f"Demonstration finished. Result: {result}")
    print(f"\nLogs (e.g., .robocorp_log, .html) can be found in: {log_output_dir.absolute()}")
    print("To view structured logs, use Robocorp Lab or a compatible viewer.")

view raw JSON →