/

Configuration

Configuration

Configure ByteHide Logs using the LogSettings class to customize logging behavior across your application.

LogSettings Class

The LogSettings class provides a comprehensive configuration interface for all logging features:

Python
from bytehide_logs import LogSettings, LogLevel, RollingInterval
from datetime import timedelta

settings = LogSettings(
    console_enabled=True,
    minimum_level=LogLevel.INFO,
    include_caller_info=True,
    persist=False,
    file_path="/var/log/app.log",
    rolling_interval=RollingInterval.DAY,
    roll_on_file_size_limit=True,
    file_size_limit_bytes=10485760,  # 10MB
    mask_sensitive_data=["password", "token", "api_key"],
    duplicate_suppression_window=timedelta(seconds=5)
)

Properties Reference

PropertyTypeDefaultDescription
console_enabledboolTrueEnable logging to console
minimum_levelLogLevelLogLevel.INFOMinimum log level to record
include_caller_infoboolFalseInclude filename and line number
persistboolFalsePersist logs to file
file_pathstrNonePath to log file
rolling_intervalRollingIntervalRollingInterval.DAYRotation interval for log files
roll_on_file_size_limitboolFalseRotate when file size exceeded
file_size_limit_bytesint104857600Maximum file size (100MB)
mask_sensitive_datalist[]Keywords to mask in logs
duplicate_suppression_windowtimedeltaNoneSuppress duplicate messages window

Usage Examples

Minimal Configuration

Python
from bytehide_logs import Log, LogSettings

settings = LogSettings(console_enabled=True)
Log.initialize(settings)

Production Configuration

Python
from bytehide_logs import Log, LogSettings, LogLevel, RollingInterval
from datetime import timedelta

settings = LogSettings(
    console_enabled=False,  # Disable console output
    persist=True,           # Enable file logging
    file_path="/var/log/myapp/app.log",
    minimum_level=LogLevel.WARN,  # Only WARN and above
    include_caller_info=True,  # Include source information
    rolling_interval=RollingInterval.DAY,  # Rotate daily
    roll_on_file_size_limit=True,  # Also rotate on size
    file_size_limit_bytes=52428800,  # 50MB
    mask_sensitive_data=["password", "token", "api_key", "secret"],
    duplicate_suppression_window=timedelta(seconds=10)
)

Log.set_project_token("your-project-token")
Log.initialize(settings)

Development Configuration

Python
from bytehide_logs import Log, LogSettings, LogLevel

settings = LogSettings(
    console_enabled=True,  # See logs in console
    minimum_level=LogLevel.DEBUG,  # All messages
    include_caller_info=True,  # Know where logs come from
    persist=False  # No file persistence
)

Log.initialize(settings)

Combined Console and File

Python
from bytehide_logs import Log, LogSettings, LogLevel, RollingInterval

settings = LogSettings(
    console_enabled=True,  # Output to console
    persist=True,          # Also write to file
    file_path="./logs/app.log",
    minimum_level=LogLevel.INFO,
    rolling_interval=RollingInterval.HOUR,
    include_caller_info=True
)

Log.initialize(settings)

Log Levels

ByteHide Logs supports six severity levels:

Python
from bytehide_logs import LogLevel

LogLevel.TRACE      # Detailed debugging information
LogLevel.DEBUG      # Diagnostic information
LogLevel.INFO       # General informational messages
LogLevel.WARN       # Warning messages
LogLevel.ERROR      # Error messages
LogLevel.CRITICAL   # Critical system failures

Sensitive Data Masking

Protect sensitive information by specifying keywords that should be masked:

Python
settings = LogSettings(
    mask_sensitive_data=[
        "password",
        "api_key",
        "token",
        "secret",
        "credit_card",
        "ssn"
    ]
)

Any log message containing these keywords will have the values masked with ***.

Duplicate Suppression

Suppress identical log messages within a time window:

Python
from datetime import timedelta

settings = LogSettings(
    duplicate_suppression_window=timedelta(seconds=5)
)

Log.initialize(settings)

Log.warn("Database timeout")  # Logged
Log.warn("Database timeout")  # Suppressed (within 5 seconds)
Log.warn("Database timeout")  # Logged (after 5 second window)

Caller Information

Include the filename and line number in logs:

Python
settings = LogSettings(include_caller_info=True)

# Output will include: app.py:42 [INFO] Message

Rolling Intervals

Control how log files rotate with RollingInterval:

Python
from bytehide_logs import RollingInterval

RollingInterval.MINUTE   # Rotate every minute
RollingInterval.HOUR     # Rotate every hour
RollingInterval.DAY      # Rotate daily
RollingInterval.WEEK     # Rotate weekly
RollingInterval.MONTH    # Rotate monthly
RollingInterval.YEAR     # Rotate yearly

Next Steps

Previous
Installation