Package: beans-logging
beans_loggingbeans_loggingis a python package for simple logger and easily managing logging modules.It is aLogurubased custom logging package for python projects.FeaturesMainloggerbased onLogurulogging -https://pypi.org/project/loguruLogging tolog files(all, error, json)Pre-definedlogging configs and handlersColorfulloggingAutointerceptingandmutingmodulesLoad config fromYAMLorJSONfileCustom options as aconfigCustom loggingformatsMultiprocesscompatibility (Linux, macOS - 'fork')Add customhandlersBaselogging moduleSupportPydantic-v1andPydantic-v2Installation1. PrerequisitesPython (>= v3.8)PyPi (>= v23)2. Install beans-logging packageChoose one of the following methods to install the package[A ~ F]:A.[RECOMMENDED] Install fromPyPi# Install or upgrade beans-logging package:pipinstall-Ubeans-loggingB.Install latest version fromGitHub# Install package by git:pipinstallgit+https://github.com/bybatkhuu/module.python-logging.gitC.Install frompre-built releasefilesDownload.whlor.tar.gzfile fromreleases-https://github.com/bybatkhuu/module.python-logging/releasesInstall with pip:# Install from .whl file:pipinstall./beans_logging-[VERSION]-py3-none-any.whl# Or install from .tar.gz file:pipinstall./beans_logging-[VERSION].tar.gzD.Install fromsource codeby building package# Clone repository by git:gitclonehttps://github.com/bybatkhuu/module.python-logging.gitbeans_loggingcd./beans_logging# Install python build tool:pipinstall-Upipbuild# Build python package:python-mbuild_VERSION=$(./scripts/get-version.sh)# Install from .whl file:pipinstall./dist/beans_logging-${_VERSION}-py3-none-any.whl# Or install from .tar.gz file:pipinstall./dist/beans_logging-${_VERSION}.tar.gzE.Install with pip editabledevelopment mode(from source code)# Clone repository by git:gitclonehttps://github.com/bybatkhuu/module.python-logging.gitbeans_loggingcd./beans_logging# Install with editable development mode:pipinstall-e.F.Manually add toPYTHONPATH(not recommended)# Clone repository by git:gitclonehttps://github.com/bybatkhuu/module.python-logging.gitbeans_loggingcd./beans_logging# Install python dependencies:pipinstall-r./requirements.txt# Add current path to PYTHONPATH:exportPYTHONPATH="${PWD}:${PYTHONPATH}"Usage/ExamplesTo usebeans_logging, import theloggerinstance from thebeans_logging.autopackage:frombeans_logging.autoimportloggerYou can call logging methods directly from theloggerinstance:logger.info("Logging info.")Simpleconfigs/logger.yml:logger:
  app_name: "my-app"
  level: "TRACE"
  file:
    log_handlers:
      enabled: true
    json_handlers:
      enabled: truemain.py:frombeans_logging.autoimportloggerlogger.trace("Tracing...")logger.debug("Debugging...")logger.info("Logging info.")logger.success("Success.")logger.warning("Warning something.")logger.error("Error occured.")logger.critical("CRITICAL ERROR.")defdivide(a,b):_result=a/breturn_resultdefnested(c):try:divide(5,c)exceptZeroDivisionErroraserr:logger.error(err)raisetry:nested(0)exceptExceptionaserr:logger.exception("Show me, what value is wrong:")Run theexamples/simple:cd./examples/simple

python./main.pyOutput:[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
[2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
[2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
[2023-09-01 00:00:00.000 +09:00 | INFO  | __main__:9]: Logging info.
[2023-09-01 00:00:00.000 +09:00 | OK    | __main__:10]: Success.
[2023-09-01 00:00:00.000 +09:00 | WARN  | __main__:11]: Warning something.
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
[2023-09-01 00:00:00.000 +09:00 | CRIT  | __main__:13]: CRITICAL ERROR.
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
Traceback (most recent call last):

> File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
    nested(0)
    └ <function nested at 0x10802a4c0>

  File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
    divide(5, c)
    │         └ 0
    └ <function divide at 0x1052f31f0>

  File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
    _result = a / b
              │   └ 0
              └ 5

ZeroDivisionError: division by zeroFastAPICheckoutbeans_logging_fastapipackage:https://github.com/bybatkhuu/module.fastapi-loggingFastAPI HTTP access logging middlewareInstall with pip:pip install -U beans-logging[fastapi]orpip install -U beans-logging-fastapiRunning TestsTo run tests, run the following command:# Install python test dependencies:pipinstall-r./requirements.test.txt# Run tests:python-mpytest-vEnvironment VariablesYou can use the following environment variables inside.env.examplefile:ENV=developmentDEBUG=trueBEANS_LOGGING_DISABLE_DEFAULT=falseBEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"BEANS_LOGGING_LOGS_DIR="./logs"ConfigurationYou can use the following configuration templatelogger.yml: file:logger:# app_name: "app"level:"INFO"use_diagnose:falsestream:use_color:trueuse_icon:falseformat_str:"[<c>{time:YYYY-MM-DDHH:mm:ss.SSSZ}</c>|<level>{level_short:<5}</level>|<w>{name}:{line}</w>]:<level>{message}</level>"std_handler:enabled:truefile:logs_dir:"./logs"rotate_size:10000000# 10MBrotate_time:"00:00:00"backup_count:90log_handlers:enabled:falseformat_str:"[{time:YYYY-MM-DDHH:mm:ss.SSSZ}|{level_short:<5}|{name}:{line}]:{message}"log_path:"{app_name}.std.all.log"err_path:"{app_name}.std.err.log"json_handlers:enabled:falseuse_custom:falselog_path:"{app_name}.json.all.log"err_path:"{app_name}.json.err.log"intercept:auto_load:enabled:trueonly_base:falseignore_modules:[]include_modules:[]mute_modules:[]extra:DocumentationdocsscriptsReferenceshttps://github.com/Delgan/loguruhttps://loguru.readthedocs.io/en/stable/api/logger.htmlhttps://loguru.readthedocs.io/en/stable/resources/recipes.htmlhttps://github.com/bybatkhuu/module.fastapi-logging