Code Monkey home page Code Monkey logo

gqylpy-log's Introduction

LOGO Release Python Versions License Downloads

gqylpy-log

English | δΈ­ζ–‡

gqylpy-log is a secondary encapsulation of logging that allows for more convenient and quick creation of loggers. Using the gqylpy_log module, you can rapidly create logging.Logger instances and complete a series of logging configurations, making your code cleaner.

pip3 install gqylpy_log

Using the Built-in Logger

gqylpy_log comes with a built-in logger based on logging.StreamHandler. You can directly call it as follows:

import gqylpy_log as glog

glog.debug(...)
glog.info(...)
glog.warning(...)
glog.error(...)
glog.critical(...)

Its default configuration is as follows:

{
    "level": "NOTSET",
    "formatter": {
        "fmt": "[%(asctime)s] [%(module)s.%(funcName)s.line%(lineno)d] "
               "[%(levelname)s] %(message)s",
        "datefmt": "%F %T"
    },
    "handlers": [{"name": "StreamHandler"}]
}

You can adjust the default logger configuration as needed:

glog.default["level"] = "INFO"

However, please note that the default logger is created the first time a logging method is called. To make changes effective, you must modify the configuration before the first call.

Creating a New Logger

The following example demonstrates how to obtain a logger with three handlers:

import gqylpy_log as glog

log: logging.Logger = glog.__init__(
    "alpha",
    level="DEBUG",
    formatter={"fmt": "[%(asctime)s] [%(levelname)s] %(message)s"},
    handlers=[
        {"name": "StreamHandler"},
        {
            "name": "FileHandler",
            "level": "ERROR",
            "filename": "/var/log/alpha/error.log",
            "encoding": "UTF-8",
            "formatter": {"fmt": "[%(asctime)s] %(message)s", "datefmt": "%c"},
            "options": {"onlyRecordCurrentLevel": True}
        },
        {
            "name": "TimedRotatingFileHandler",
            "level": "INFO",
            "filename": "/var/log/alpha/alpha.log",
            "encoding": "UTF-8",
            "when": "D",
            "interval": 1,
            "backupCount": 7
        }
    ]
)

log.info(...)

Alternatively, if you prefer to always call it through the gqylpy_log module, specify the gname parameter:

glog.__init__(..., gname="alpha")

Please note that specifying the gname parameter will override and permanently disable the default logger.

gqylpy-log's People

Contributors

2018-11-27 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.