2626import datetime
2727import logging
2828from pathlib import Path
29-
29+ from src . ansys . tools . common . logger_formatter import DEFAULT_FORMATTER
3030
3131class SingletonType (type ):
3232 """Provides the singleton helper class for the logger."""
@@ -40,53 +40,6 @@ def __call__(cls, *args, **kwargs):
4040 return cls ._instances [cls ]
4141
4242
43- class CustomFormatter (logging .Formatter ):
44- """Custom formatter to truncate long columns."""
45-
46- def set_column_width (self , width : int ):
47- """Set the maximum column width for module and function names."""
48- # at least 8
49- if width < 8 :
50- raise ValueError ("Column width must be at least 8 characters." )
51- self ._max_column_width = width
52-
53- @property
54- def max_column_width (self ):
55- """Get the maximum column length."""
56- if not hasattr (self , "_max_column_width" ):
57- self ._max_column_width = 15
58- return self ._max_column_width
59-
60- def format (self , record ):
61- """Format the log record, truncating the module and function names if necessary."""
62- if len (record .module ) > self .max_column_width :
63- record .module = record .module [: self .max_column_width - 3 ] + "..."
64- if len (record .funcName ) > self .max_column_width :
65- record .funcName = record .funcName [: self .max_column_width - 3 ] + "..."
66-
67- # Fill the module and function names with spaces to align them
68- record .module = record .module .ljust (self .max_column_width )
69- record .funcName = record .funcName .ljust (self .max_column_width )
70-
71- return super ().format (record )
72-
73-
74- DEFAULT_FORMATTER = CustomFormatter (
75- "%(asctime)s [%(levelname)-8s | %(module)s | %(funcName)s:%(lineno)-4d] > %(message)s"
76- )
77- DEFAULT_FORMATTER .set_column_width (15 )
78- """Default formatter for the logger."""
79-
80- DEFAULT_HEADER = (
81- "-" * (70 + DEFAULT_FORMATTER .max_column_width )
82- + "\n "
83- + f"Timestamp [Level | Module{ ' ' * (DEFAULT_FORMATTER .max_column_width - 6 )} | Function{ ' ' * (DEFAULT_FORMATTER .max_column_width - 8 )} :Line] > Message\n " # noqa: E501
84- + "-" * (70 + DEFAULT_FORMATTER .max_column_width )
85- + "\n "
86- )
87- """Default header for the log file."""
88-
89-
9043class Logger (object , metaclass = SingletonType ):
9144 """Provides the singleton logger.
9245
0 commit comments