A python logging wrapper
Project description
log2file
python 自带 logging 模块的一个封装 自己的项目经常用,每次都配置一堆很麻烦,就自己封装了一个。
安装
pip install log2file
使用
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import log2file
import logging
# from multiprocessing import Pool
from multiprocessing.dummy import Pool
import time
import random
log2file.init(console=True, name="test")
# for root logger, don't use this or you will get many many logs,and all other loggers will be shadowed by root logger
# log2file.init(console=True)
trace_test = log2file.trace(name="test")
# this is the trace for root logger, don't use this if you have not init root logger
trace_root = log2file.trace()
for i in range(20):
log2file.init(console=True, name=str(i))
for i in range(20):
log2file.init(console=True, name=str(i))
@trace_test("test_test111")
def s():
time.sleep(0.1 + random.randint(0, 100) / 1000)
@trace_root("root_debug")
def s2():
time.sleep(0.1 + random.randint(0, 100) / 1000)
def fun(t):
log = logging.getLogger(name=str(t))
for i in range(100):
s()
log.debug("this is a test [{0}]-[{1}]".format(t, i))
s2()
p = Pool(10)
p.map(fun, range(20))
p.close()
p.join()
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
log2file-1.4.tar.gz
(3.7 kB
view details)
File details
Details for the file log2file-1.4.tar.gz
.
File metadata
- Download URL: log2file-1.4.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7bae5813b3b5bdea9faa9bbfb1885d46107e07e7077f92a9cd61fcc3e214b7d |
|
MD5 | becba3eb678a60bb6b9938da97ec4c27 |
|
BLAKE2b-256 | 75b477824bbc4525ebb085a7889a7f3917cc78ed6dfe81cb8f10266d0e548516 |