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)
)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
| Property | Type | Default | Description |
|---|---|---|---|
console_enabled | bool | True | Enable logging to console |
minimum_level | LogLevel | LogLevel.INFO | Minimum log level to record |
include_caller_info | bool | False | Include filename and line number |
persist | bool | False | Persist logs to file |
file_path | str | None | Path to log file |
rolling_interval | RollingInterval | RollingInterval.DAY | Rotation interval for log files |
roll_on_file_size_limit | bool | False | Rotate when file size exceeded |
file_size_limit_bytes | int | 104857600 | Maximum file size (100MB) |
mask_sensitive_data | list | [] | Keywords to mask in logs |
duplicate_suppression_window | timedelta | None | Suppress duplicate messages window |
Usage Examples
Minimal Configuration
Python
from bytehide_logs import Log, LogSettings
settings = LogSettings(console_enabled=True)
Log.initialize(settings)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)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)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)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 failuresfrom 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 failuresSensitive 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"
]
)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)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] Messagesettings = LogSettings(include_caller_info=True)
# Output will include: app.py:42 [INFO] MessageRolling 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 yearlyfrom 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 yearlyNext Steps
- Quick Start - Initialize logging in your app
- Project Token - Configure credentials
- File Logging - Advanced file configuration