nglcobdai_utils.log

class StringLogHandler[source]

Bases: Handler

emit(record)[source]

Emit log

Parameters:

record (logging.LogRecord) – Log record

get_log_message()[source]

Get last log message

class HandlerInfo(*, is_use: bool = True, log_level: str = 'INFO', format: str = '%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s')[source]

Bases: BaseModel

Handler information

Parameters:
  • is_use (bool) – Whether to use the handler.

  • log_level (str) – Log level.

  • format (str) – Log format. (default: “%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s”)

is_use: bool
log_level: str
format: str
get_param()[source]

Get handler parameters

Returns:

Handler parameters

Return type:

Dict

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'format': FieldInfo(annotation=str, required=False, default='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s'), 'is_use': FieldInfo(annotation=bool, required=False, default=True), 'log_level': FieldInfo(annotation=str, required=False, default='INFO')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class ConsoleHandlerInfo(*, is_use: bool = True, log_level: str = 'INFO', format: str = '%(asctime)s : %(levelname)s : %(filename)s - %(message)s')[source]

Bases: HandlerInfo

Console handler information

Parameters:

format (str, optional) – Log format. (default: “%(asctime)s : %(levelname)s : %(filename)s - %(message)s”)

format: str
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'format': FieldInfo(annotation=str, required=False, default='%(asctime)s : %(levelname)s : %(filename)s - %(message)s'), 'is_use': FieldInfo(annotation=bool, required=False, default=True), 'log_level': FieldInfo(annotation=str, required=False, default='INFO')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class FileHandlerInfo(*, is_use: bool = True, log_level: str = 'INFO', format: str = '%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s', filename: str | Path = PosixPath('/root/logs/default.log'), encoding: str = 'utf-8')[source]

Bases: HandlerInfo

File handler information

Parameters:
  • filename (str | pathlib.Path, optional) – Path of the log file. (default: “~/logs/test.log”)

  • encoding (str, optional) – Encoding of the log file. (default: “utf-8”)

encoding: str
filename: str | Path
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'encoding': FieldInfo(annotation=str, required=False, default='utf-8'), 'filename': FieldInfo(annotation=Union[str, Path], required=False, default=PosixPath('/root/logs/default.log')), 'format': FieldInfo(annotation=str, required=False, default='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s'), 'is_use': FieldInfo(annotation=bool, required=False, default=True), 'log_level': FieldInfo(annotation=str, required=False, default='INFO')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class TimedRotatingFileHandlerInfo(*, is_use: bool = True, log_level: str = 'INFO', format: str = '%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s', filename: str | Path = PosixPath('/root/logs/default.log'), encoding: str = 'utf-8', backupCount: int = 5, when: str = 'D', interval: int = 1, atTime: time = datetime.time(0, 0), utc: bool = False)[source]

Bases: FileHandlerInfo

Time rotating file handler information

Parameters:
  • backupCount (int) – Number of backup files. (default: 5)

  • when (str) – Type of interval. (default: “D”)

  • interval (int) – Interval of rotation. (default: 1)

  • atTime (datetime.time) – JTC time to rotate. (default: datetime.time(0, 0, 0))

  • utc (bool) – Whether to use UTC time. (default: False)

backupCount: int
when: str
interval: int
atTime: time
utc: bool
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'atTime': FieldInfo(annotation=time, required=False, default=datetime.time(0, 0)), 'backupCount': FieldInfo(annotation=int, required=False, default=5), 'encoding': FieldInfo(annotation=str, required=False, default='utf-8'), 'filename': FieldInfo(annotation=Union[str, Path], required=False, default=PosixPath('/root/logs/default.log')), 'format': FieldInfo(annotation=str, required=False, default='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s'), 'interval': FieldInfo(annotation=int, required=False, default=1), 'is_use': FieldInfo(annotation=bool, required=False, default=True), 'log_level': FieldInfo(annotation=str, required=False, default='INFO'), 'utc': FieldInfo(annotation=bool, required=False, default=False), 'when': FieldInfo(annotation=str, required=False, default='D')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class RotatingFileHandlerInfo(*, is_use: bool = True, log_level: str = 'INFO', format: str = '%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s', filename: str | Path = PosixPath('/root/logs/default.log'), encoding: str = 'utf-8', backupCount: int = 5, maxBytes: int = 10485760)[source]

Bases: FileHandlerInfo

Rotating file handler information

Parameters:
  • backupCount (int) – Number of backup files. (default: 5)

  • maxBytes (int) – Maximum size of the log file. (default: 10485760)

backupCount: int
maxBytes: int
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'backupCount': FieldInfo(annotation=int, required=False, default=5), 'encoding': FieldInfo(annotation=str, required=False, default='utf-8'), 'filename': FieldInfo(annotation=Union[str, Path], required=False, default=PosixPath('/root/logs/default.log')), 'format': FieldInfo(annotation=str, required=False, default='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s'), 'is_use': FieldInfo(annotation=bool, required=False, default=True), 'log_level': FieldInfo(annotation=str, required=False, default='INFO'), 'maxBytes': FieldInfo(annotation=int, required=False, default=10485760)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class StringHandlerInfo(*, is_use: bool = True, log_level: str = 'INFO', format: str = '%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s')[source]

Bases: HandlerInfo

String handler information

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'format': FieldInfo(annotation=str, required=False, default='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s'), 'is_use': FieldInfo(annotation=bool, required=False, default=True), 'log_level': FieldInfo(annotation=str, required=False, default='INFO')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class CustomLogger(name)[source]

Bases: Logger

__init__(name)[source]

Constructor of CustomLogger

Parameters:

name (str) – Name of the logger.

settting_logger(ch_info, fh_info, sh_info)[source]

Set logger

Parameters:
get_log_message()[source]

Get last log message

get_logger(name, ch_info=ConsoleHandlerInfo(is_use=False, log_level='INFO', format='%(asctime)s : %(levelname)s : %(filename)s - %(message)s'), fh_info=FileHandlerInfo(is_use=False, log_level='INFO', format='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s', filename=PosixPath('/root/logs/default.log'), encoding='utf-8'), sh_info=StringHandlerInfo(is_use=False, log_level='INFO', format='%(asctime)s - %(levelname)s - %(filename)s - %(name)s - %(funcName)s - %(message)s'))[source]

Retrieve a configured logger.

Parameters:

Example

>>> console_handler_info = ConsoleHandlerInfo(log_level="INFO")
>>> file_handler_info = FileHandlerInfo(log_level="DEBUG", filename="~/logs/test.log")
>>> string_handler_info = StringHandlerInfo(log_level="DEBUG")
>>> logger = get_logger(
...     name="test_logger",
...     ch_info=console_handler_info,
...     fh_info=file_handler_info,
...     sh_info=string_handler_info,
... )
Returns:

The configured logger instance.

Return type:

logging.Logger