freeports_analysis.logging

Module containing useful definitions for program logging configuration.

This module provides custom logging formatters, filters, and configuration for the standard logging Python package, tailored for PDF processing and financial data extraction workflows.

Functions

log_config(logger, config, config_location)

Log with debug priority the configuration provided.

Classes

AdaptStandardInvesmentInfos([name])

Filter that adds algorithm-specific investment information to LogRecords.

AddContextualInfos([name])

Filter that adds contextual state information to LogRecords.

CsvFormatter([fmt, datefmt, style, ...])

Formatter for CSV file logging with PDF document position information.

DevDebugFormatter([fmt, datefmt, style, ...])

Formatter class for comprehensive debug logging with full location information.

StderrFormatter([fmt, datefmt, style, ...])

Formatter class for concise single-line logging suitable for live streams like stderr.

class freeports_analysis.logging.AdaptStandardInvesmentInfos(name='')

Filter that adds algorithm-specific investment information to LogRecords.

This filter adds information specific to the standard PDF processing algorithms (standard_pdf_filtering, standard_text_extracting, standard_deserialization) and converts it to a less algorithm-dependent format suitable for the AddContextualInfos filter.

company

The company being parsed as recognized by the algorithm

Type:

Optional[str]

company_match

The company being parsed as written in the PDF document

Type:

Optional[str]

field

The field being parsed

Type:

Optional[str]

row

The row number in the body table (investment table)

Type:

Optional[int]

col

The column number in the body table

Type:

Optional[int]

filter(record: LogRecord) LogRecord

Add investment-specific information and convert to contextual format.

Parameters:

record (logging.LogRecord) – The log record to enrich with investment information

Returns:

The enriched log record with investment context

Return type:

logging.LogRecord

class freeports_analysis.logging.AddContextualInfos(name='')

Filter that adds contextual state information to LogRecords.

This filter maintains state about the processing context and adds this information to log records for better traceability and debugging.

mproc

If True, indicates multiprocess mode (requires PID identification)

Type:

bool

batch_mode

If True, indicates batch processing mode (requires report identification)

Type:

bool

page

The PDF page number being parsed

Type:

Optional[int]

report

The identifier of the specific PDF report (uses PREFIX_OUT)

Type:

Optional[str]

vertical_ref

Textual hint for vertical position in page (e.g., company name)

Type:

Optional[str]

horizontal_ref

Textual hint for horizontal position in page

Type:

Optional[str]

c1

First coordinate for precise position identification

Type:

Optional[Union[float, int]]

c2

Second coordinate for precise position identification

Type:

Optional[Union[float, int]]

filter(record: LogRecord) LogRecord

Add contextual information from filter state to the LogRecord.

Parameters:

record (logging.LogRecord) – The log record to enrich with contextual information

Returns:

The enriched log record with contextual information

Return type:

logging.LogRecord

class freeports_analysis.logging.CsvFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Formatter for CSV file logging with PDF document position information.

This formatter produces CSV-formatted log entries containing information primarily related to PDF document positions, making it suitable for user review rather than developer debugging.

None

Inherits all attributes from logging.Formatter

format(record: LogRecord) str

Format the log record as CSV with PDF position information.

Parameters:

record (logging.LogRecord) – The log record to format

Returns:

CSV-formatted log entry

Return type:

str

Notes

The CSV output includes fields for: - Page number - Row and column coordinates - Log message - Report identifier (in batch mode)

class freeports_analysis.logging.DevDebugFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Formatter class for comprehensive debug logging with full location information.

This formatter is useful for debugging purposes as it provides detailed information about code location and PDF document position.

None

Inherits all attributes from logging.Formatter

format(record: LogRecord) str

Format log record with full information on code and PDF document location.

Parameters:

record (logging.LogRecord) – The log record to format

Returns:

Formatted debug message with comprehensive location information

Return type:

str

Notes

The formatted output includes: - Process ID (if multiprocessing) - Log level and source location (function, line, file) - Report and page context - PDF document coordinates and position references - The actual log message

class freeports_analysis.logging.StderrFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Formatter class for concise single-line logging suitable for live streams like stderr.

This formatter produces compact log messages ideal for real-time monitoring and command-line output.

None

Inherits all attributes from logging.Formatter

format(record: LogRecord) str

Format the log as a concise one-line message for live stream display.

Parameters:

record (logging.LogRecord) – The log record to format

Returns:

Compact formatted log message

Return type:

str

Notes

The formatted output includes minimal context: - Process ID (if multiprocessing) - Log level - Report and page context (if available) - Position references (if available) - The actual log message

freeports_analysis.logging.log_config(logger: Logger, config: Dict[str, Any], config_location: Dict[str, str]) None

Log with debug priority the configuration provided.

Parameters:
  • logger (logging.Logger) – the logger that has to log

  • config (Dict[str, Any]) – The configuration dictionary to log

  • config_location (Dict[str, str]) – Dictionary mapping configuration keys to their source locations