Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
karaposu committed Oct 16, 2024
1 parent c1d0db5 commit f3f69e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 14 additions & 4 deletions indented_logger/formatter.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# here is formatter.py
# formatter.py

import logging
from .indent import get_indent_level

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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -104,4 +114,4 @@ def format(self, record):
finally:
# Restore the original message and arguments
record.msg = original_msg
record.args = original_args
record.args = original_args
9 changes: 5 additions & 4 deletions indented_logger/logging_config.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3f69e9

Please sign in to comment.