diff --git a/indented_logger/formatter.py b/indented_logger/formatter.py index 8ee1abd..8a5ef9e 100644 --- a/indented_logger/formatter.py +++ b/indented_logger/formatter.py @@ -1,4 +1,4 @@ -# here is formatter.py +# formatter.py import logging from .indent import get_indent_level @@ -6,13 +6,14 @@ class IndentFormatter(logging.Formatter): def __init__(self, include_func=False, include_module=False, func_module_format=None, truncate_messages=False, min_func_name_col=80, use_logger_hierarchy=False, - datefmt=None, indent_spaces=4): + datefmt=None, indent_spaces=4, debug=False): self.include_func = include_func self.include_module = include_module self.truncate_messages = truncate_messages self.min_func_name_col = min_func_name_col self.use_logger_hierarchy = use_logger_hierarchy self.indent_spaces = indent_spaces + self.debug = debug # New debug flag # Dynamically build the func_module_format based on include flags if func_module_format is None: @@ -70,12 +71,21 @@ def format(self, record): # Build the base log line without func_module_info base_log = f"{asctime} - {levelname} - {message}" + # Add debug statements if debug mode is enabled + if self.debug: + print("DEBUG: record.name =", record.name) + print("DEBUG: record.funcName =", record.funcName) + print("DEBUG: func_module_format =", self.func_module_format) + # Build the func_module_info string based on the format provided if self.func_module_format: func_module_info = self.func_module_format.format( funcName=record.funcName, - moduleName=record.name # This is the logger's name, typically the module name + moduleName=record.name ) + if self.debug: + print("DEBUG: func_module_info =", func_module_info) + record.func_module_info = func_module_info # Calculate padding to align func_module_info at min_func_name_col @@ -104,4 +114,4 @@ def format(self, record): finally: # Restore the original message and arguments record.msg = original_msg - record.args = original_args \ No newline at end of file + record.args = original_args diff --git a/indented_logger/logging_config.py b/indented_logger/logging_config.py index 239c534..582a189 100644 --- a/indented_logger/logging_config.py +++ b/indented_logger/logging_config.py @@ -1,11 +1,11 @@ -# here is logging_config.py +# logging_config.py import logging from .formatter import IndentFormatter def setup_logging(level=logging.DEBUG, log_file=None, include_func=False, include_module=False, - func_module_format='{funcName}', truncate_messages=False, min_func_name_col=80, - use_logger_hierarchy=False, indent_spaces=4, datefmt=None): + func_module_format=None, truncate_messages=False, min_func_name_col=80, + use_logger_hierarchy=False, indent_spaces=4, datefmt=None, debug=False): # Create the formatter with the new parameters formatter = IndentFormatter( include_func=include_func, @@ -15,7 +15,8 @@ def setup_logging(level=logging.DEBUG, log_file=None, include_func=False, includ min_func_name_col=min_func_name_col, use_logger_hierarchy=use_logger_hierarchy, indent_spaces=indent_spaces, - datefmt=datefmt + datefmt=datefmt, + debug=debug # Pass the debug flag ) # Get the root logger diff --git a/setup.py b/setup.py index 7d18f18..02b577b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='indented_logger', # Package name - version='0.2.2', # Version of your package + version='0.2.3', # Version of your package author='Enes Kuzucu', # Your name description='A module to use common logger module with indentation support ', # Short description