The brightest kid in python log is the fancy acridine

It seems that this log module can't be downloaded in the mirror station of Tsinghua University. Other mirror stations haven't tried it. I downloaded it directly from the address of the official website

[read the full text]

C:\Users\Administrator>pip install nb_log
Collecting nb_log
  Downloading nb_log-7.2.tar.gz (71 kB)
     |████████████████████████████████| 71 kB 17 kB/s
Collecting pymongo==3.5.1
  Downloading pymongo-3.5.1.tar.gz (1.3 MB)
     |████████████████████████████████| 1.3 MB 53 kB/s
Collecting tomorrow3==1.1.0
  Downloading tomorrow3-1.1.0.tar.gz (1.2 kB)
Collecting concurrent-log-handler==0.9.19
  Downloading concurrent_log_handler-0.9.19-py2.py3-none-any.whl (18 kB)
Collecting elasticsearch
  Downloading elasticsearch-7.17.0-py2.py3-none-any.whl (385 kB)
     |████████████████████████████████| 385 kB 21 kB/s
Collecting kafka-python==1.4.6
  Downloading kafka_python-1.4.6-py2.py3-none-any.whl (259 kB)
     |████████████████████████████████| 259 kB 36 kB/s
Requirement already satisfied: requests in c:\python38\lib\site-packages (from nb_log) (2.25.1)
Collecting pika
  Downloading pika-1.2.0-py2.py3-none-any.whl (154 kB)
     |████████████████████████████████| 154 kB 58 kB/s
Requirement already satisfied: flask in c:\python38\lib\site-packages (from nb_log) (1.1.2)
Collecting python-json-logger==0.1.10
  Downloading python_json_logger-0.1.10-py2.py3-none-any.whl (5.0 kB)
Collecting nb_filelock
  Downloading nb_filelock-0.7.tar.gz (4.8 kB)

It's easy to use. Just call it directly after setting.

from nb_log import LogManager  # Import nb_log module LogManager

Set console printing. The log name here is: log module test project.

logger = LogManager('Log module test items').get_logger_and_add_handlers()

Printing effect in various modes.

logger.debug('debug Log printing mode......')
logger.info('info Log printing mode......')
logger.warn('warn Log printing mode......')
logger.error('error Log printing mode......')
logger.critical('critical Log printing mode......')

It's good to use the default configuration directly when printing the log. In order to adjust it to your favorite appearance, you can modify the status in the configuration file.

After starting the program, py and Nb will be automatically generated under the root directory_ log_ config. Py file. The root directory here refers to the root directory of the project, not the directory of the current program file.

Modify NB_ log_ config. Whether the status of several variables in py is on or not.

DEFAULUT_USE_COLOR_HANDLER = True  # Whether to use colored logs by default.
DISPLAY_BACKGROUD_COLOR_IN_CONSOLE = False  # Whether the color block log is displayed on the console. False does not use a large background color.
AUTO_PATCH_PRINT = True  # Whether to automatically apply the monkey patch of print. If the monkey patch is applied, the print will automatically change color and click to jump.
SHOW_PYCHARM_COLOR_SETINGS = True  # Some people are disgusted that the prompt when starting the code teaches you how to optimize the pycahrm console color. You can set this to False

Each status has detailed Chinese comments, which can be modified according to your preferences. I only changed the background color to False.

In addition, you can also modify the printing template, that is, what information to print, such as time, etc. Also modify nb_log_config.py file.

FORMATTER_KIND = 5 # if get_ If the logger does not specify a log template, the first one is selected by default. A total of 11 template styles can be selected in NB_ log_ config. You can see it in the PY file. Which format do you need_ Just change the value of kind to a few.

FORMATTER_DICT = {
    1: logging.Formatter(
        'Log time[%(asctime)s] - Log name[%(name)s] - Documents[%(filename)s] - The first[%(lineno)d]that 's ok - Log level[%(levelname)s] - Log information[%(message)s]',
        "%Y-%m-%d %H:%M:%S"),
    2: logging.Formatter(
        '%(asctime)s - %(name)s - %(filename)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s',
        "%Y-%m-%d %H:%M:%S"),
    3: logging.Formatter(
        '%(asctime)s - %(name)s - [ File "%(pathname)s", line %(lineno)d, in %(funcName)s ] - %(levelname)s - %(message)s',
        "%Y-%m-%d %H:%M:%S"),  # A template that mimics the traceback exception and can jump to the place where the log is printed
    4: logging.Formatter(
        '%(asctime)s - %(name)s - "%(filename)s" - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s -               File "%(pathname)s", line %(lineno)d ',
        "%Y-%m-%d %H:%M:%S"),  # This also supports log jump
    5: logging.Formatter(
        '%(asctime)s - %(name)s - "%(pathname)s:%(lineno)d" - %(funcName)s - %(levelname)s - %(message)s',
        "%Y-%m-%d %H:%M:%S"),  # I think the best template is recommended
    6: logging.Formatter('%(name)s - %(asctime)-15s - %(filename)s - %(lineno)d - %(levelname)s: %(message)s',
                         "%Y-%m-%d %H:%M:%S"),
    7: logging.Formatter('%(asctime)s - %(name)s - "%(filename)s:%(lineno)d" - %(levelname)s - %(message)s', "%Y-%m-%d %H:%M:%S"),  # A log template that displays only short file names and the number of lines

    8: JsonFormatterJumpAble('%(asctime)s - %(name)s - %(levelname)s - %(message)s - "%(filename)s %(lineno)d -" ', "%Y-%m-%d %H:%M:%S", json_ensure_ascii=False),  # This is a json log for easy analysis

    9: logging.Formatter(
        '[p%(process)d_t%(thread)d] %(asctime)s - %(name)s - "%(pathname)s:%(lineno)d" - %(funcName)s - %(levelname)s - %(message)s',
        "%Y-%m-%d %H:%M:%S"),  # Improved on 5, log template with process and thread display.
    10: logging.Formatter(
        '[p%(process)d_t%(thread)d] %(asctime)s - %(name)s - "%(filename)s:%(lineno)d" - %(levelname)s - %(message)s', "%Y-%m-%d %H:%M:%S"),  # Improved on 7, log template with process and thread display.
    11: logging.Formatter(
        f'({computer_ip},{computer_name})-[p%(process)d_t%(thread)d] %(asctime)s - %(name)s - "%(filename)s:%(lineno)d" - %(levelname)s - %(message)s', "%Y-%m-%d %H:%M:%S"),  # Improvements to 7, log template with process and thread display, ip and host name.
}

If I set the log mode to 2, I feel it's easier. The effect is like this.

[previous highlights]

hashlib.md5() function to filter out system duplicate files and remove

Hassa, here comes the hero League full skin downloader

PyQt5 sensitive word detection tool production, operator's Gospel

Freehand picture generator Shuey Rhon Rhon as an example, a key to generate.

Bing dwen dwen, the mascot just released, is attached to the source.

The most beautiful form viewing plug-in: tabulate

Start! Batch add Chinese watermark to PDF file

The same tiktok roll call system is written in PyQt5, which is very simple.

On the second day of the lunar new year, I made a windows notification manager!

Baidu picture downloader 2.0

gif dynamic picture generator, multiple pictures are combined to generate dynamic pictures

python several common data processing operations, one line of code can be completed!

Keywords: Python

Added by acheoacheo on Mon, 21 Feb 2022 15:03:51 +0200