Logger Module
logger.logger
TcEx Framework Logger module
- class tcex.logger.logger.Logger(logger_name: str)[source]
Bases:
object
Framework logger module.
- _log_tc_proxy(inputs: BaseModel)[source]
Log the proxy settings.
- Parameters:
inputs – The inputs model.
- static _sanitize_proxy_url(url: Optional[str]) Optional[str] [source]
Sanitize a proxy url, masking username and password.
- add_api_handler(session_tc: Session, name: Optional[str] = 'api', level: Optional[str] = None)[source]
Add API logging handler.
- Parameters:
session_tc – An configured instance of request.Session with TC API Auth.
name – The name of the handler.
level – The level value as a string.
- add_cache_handler(name: str)[source]
Add cache logging handler.
- Parameters:
name – The name of the handler.
- add_pattern_file_handler(name: str, filename: str, level: int, path: str, pattern: str, formatter: Optional[str] = None, handler_key: Optional[str] = None, max_log_count: Optional[int] = 100, thread_key: Optional[str] = None)[source]
Add custom file logging handler.
This handler is intended for service Apps that need to log events based on the current session id. All log event would be in context to a single playbook execution.
- Parameters:
name – The name of the handler.
filename – The name of the logfile.
level – The logging level.
path – The path for the logfile.
formatter – The logging formatter to use.
handler_key – Additional properties for handler to thread condition.
max_log_count – The maximum number of logs to keep that match the provided pattern.
pattern – The pattern used to match the log files.
thread_key – Additional properties for handler to thread condition.
- add_rotating_file_handler(name: str, filename: str, path: str, backup_count: int, max_bytes: int, level: str, formatter: Optional[str] = None, mode: Optional[str] = 'a')[source]
Add custom file logging handler.
- Parameters:
name – The name of the handler.
filename – The name of the logfile.
path – The path for the logfile.
backup_count – The maximum # of backup files.
max_bytes – The max file size before rotating.
level – The logging level.
formatter – The logging formatter to use.
mode – The write mode for the file.
- add_stream_handler(name: Optional[str] = 'sh', formatter: Optional[str] = None, level: Optional[int] = None)[source]
Add stream logging handler.
- Parameters:
name – The name of the handler.
formatter – The logging formatter to use.
level – The logging level.
- add_thread_file_handler(name: str, filename: str, level: str, path: str, backup_count: Optional[int] = 0, formatter: Optional[str] = None, handler_key: Optional[str] = None, max_bytes: Optional[int] = 0, mode: Optional[str] = 'a', thread_key: Optional[str] = None)[source]
Add custom file logging handler.
This handler is intended for service Apps that need to log events based on the current trigger id. All log events would be in context to a single playbook.
- Parameters:
name – The name of the handler.
filename – The name of the logfile.
level – The logging level.
path – The path for the logfile.
backup_count – The maximum # of backup files.
formatter – The logging formatter to use.
handler_key – Additional properties for handler to thread condition.
max_bytes – The max file size before rotating.
mode – The write mode for the file.
thread_key – Additional properties for handler to thread condition.
- handler_exist(handler_name: str) bool [source]
Remove a file handler by name.
- Parameters:
handler_name – The handler name to remove.
- Returns:
True if handler current exists
- Return type:
bool
- property log: Logger
Return logger.
- log_info(inputs: BaseModel)[source]
Send System and App data to logs.
- Parameters:
inputs – The inputs model.
- static log_level(level: str) int [source]
Return proper level from string.
- Parameters:
level – The logging level.
- Returns:
The logging level as an int.
- Return type:
int
- remove_handler_by_name(handler_name: str)[source]
Remove a file handler by name.
- Parameters:
handler_name – The handler name to remove.
- replay_cached_events(handler_name: Optional[str] = 'cache')[source]
Replay cached log events and remove handler.
logger.api_handler
API Handler Class
- class tcex.logger.api_handler.ApiHandler(session, flush_limit=100)[source]
Bases:
Handler
Logger handler for ThreatConnect Exchange API logging.
- property entries
Return a copy and clear self._entries.
logger.cache_handler
Cache Handler Class
logger.rotating_file_handler_custom
API Handler Class
- class tcex.logger.rotating_file_handler_custom.RotatingFileHandlerCustom(filename: str, mode: Optional[str] = 'a', maxBytes: Optional[int] = 0, backupCount: Optional[int] = 0, encoding: Optional[str] = None, delay: Optional[bool] = False)[source]
Bases:
RotatingFileHandler
Logger handler for ThreatConnect Exchange File logging.
logger.thread_file_handler
Thread File Handler Class
- class tcex.logger.thread_file_handler.ThreadFileHandler(filename: str, mode: Optional[str] = 'a', maxBytes: Optional[int] = 0, backupCount: Optional[int] = 0, encoding: Optional[str] = None, delay: Optional[bool] = False)[source]
Bases:
RotatingFileHandler
Logger handler for ThreatConnect Exchange File logging.
- emit(record: object)[source]
Emit a record.
Emit logging events only if handler_key matches thread_key.
- Parameters:
record – The record to be logged.
- handler_key = None
- thread_key = None
logger.trace_logger
Trace Logger Class
- class tcex.logger.trace_logger.TraceLogger(name, level=0)[source]
Bases:
Logger
Add trace level to logging