Add flush for queue flushing Add set/get level for handler Allow adding handlers during launch, handlers cannot be added afterwards at the moment Add testing for LoggingLevel enum
84 lines
3.2 KiB
Python
84 lines
3.2 KiB
Python
"""
|
|
Log logging_handling.log testing
|
|
"""
|
|
|
|
# import atexit
|
|
from pathlib import Path
|
|
# this is for testing only
|
|
from corelibs.logging_handling.log import Log
|
|
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
|
|
|
|
|
def main():
|
|
"""
|
|
Log testing
|
|
"""
|
|
script_path: Path = Path(__file__).resolve().parent
|
|
log = Log(
|
|
log_path=script_path.joinpath('log', 'test.log'),
|
|
log_name="Test Log",
|
|
log_settings={
|
|
"log_level_console": 'DEBUG',
|
|
"log_level_file": 'DEBUG',
|
|
# "console_color_output_enabled": False,
|
|
}
|
|
)
|
|
|
|
log.logger.debug('[NORMAL] Debug test: %s', log.logger.name)
|
|
log.logger.info('[NORMAL] Info test: %s', log.logger.name)
|
|
log.logger.warning('[NORMAL] Warning test: %s', log.logger.name)
|
|
log.logger.error('[NORMAL] Error test: %s', log.logger.name)
|
|
log.logger.critical('[NORMAL] Critical test: %s', log.logger.name)
|
|
log.exception('[NORMAL] Exception test: %s', log.logger.name)
|
|
|
|
bad_level = 'WRONG'
|
|
if not Log.validate_log_level(bad_level):
|
|
print(f"Invalid level: {bad_level}")
|
|
good_level = 'WARNING'
|
|
if Log.validate_log_level(good_level):
|
|
print(f"Valid level: {good_level}")
|
|
|
|
print(f"ERROR is to_logging_level(): {LoggingLevel.ERROR.to_logging_level()}")
|
|
print(f"ERROR is to_lower_case(): {LoggingLevel.ERROR.to_lower_case()}")
|
|
print(f"ERROR is: {LoggingLevel.ERROR}")
|
|
print(f"ERROR is value: {LoggingLevel.ERROR.value}")
|
|
print(f"ERROR is name: {LoggingLevel.ERROR.name}")
|
|
print(f"ERROR is from_string(lower): {LoggingLevel.from_string('ERROR')}")
|
|
print(f"ERROR is from_string(upper): {LoggingLevel.from_string('ERROR')}")
|
|
print(f"ERROR is from_int: {LoggingLevel.from_int(40)}")
|
|
print(f"ERROR is from_any(text lower): {LoggingLevel.from_any('ERROR')}")
|
|
print(f"ERROR is from_any(text upper): {LoggingLevel.from_any('ERROR')}")
|
|
print(f"ERROR is from_any(int): {LoggingLevel.from_any(40)}")
|
|
print(f"INFO <= ERROR: {LoggingLevel.INFO.includes(LoggingLevel.ERROR)}")
|
|
print(f"INFO > ERROR: {LoggingLevel.INFO.is_higher_than(LoggingLevel.ERROR)}")
|
|
print(f"INFO < ERROR: {LoggingLevel.INFO.is_lower_than(LoggingLevel.ERROR)}")
|
|
print(f"INFO < ERROR: {LoggingLevel.INFO.is_lower_than(LoggingLevel.ERROR)}")
|
|
|
|
try:
|
|
print(f"INVALID is A: {LoggingLevel.from_string('INVALID')}")
|
|
except ValueError as e:
|
|
print(f"* ERROR: {e}")
|
|
|
|
try:
|
|
__test = 5 / 0
|
|
print(f"Divied: {__test}")
|
|
except ZeroDivisionError as e:
|
|
log.logger.critical("Divison through zero: %s", e)
|
|
log.exception("Divison through zero")
|
|
|
|
for handler in log.logger.handlers:
|
|
print(f"Handler (logger) {handler} -> {handler.level} -> {LoggingLevel.from_any(handler.level)}")
|
|
|
|
for key, handler in log.handlers.items():
|
|
print(f"Handler (handlers) [{key}] {handler} -> {handler.level} -> {LoggingLevel.from_any(handler.level)}")
|
|
log.set_log_level('stream_handler', LoggingLevel.ERROR)
|
|
log.logger.warning('[NORMAL] Invisible Warning test: %s', log.logger.name)
|
|
log.logger.error('[NORMAL] Visible Error test: %s', log.logger.name)
|
|
# log.handlers['stream_handler'].se
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# __END__
|