Coder Social home page Coder Social logo

xuxin8911 / python_log Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huangming/python_log

0.0 1.0 0.0 9 KB

a simple encapsulation of logging module to provide a more convenient interface to write log

License: MIT License

Python 100.00%

python_log's Introduction

python_log

a simple encapsulation of logging module to provide a more convenient interface to write log.The log will both print to stdout and write to log file. It provides a more flexible way to set the log actions, and also very simple. See examples showed below:

Example 1: Use default settings

import log
log = log.Log(cmdlevel='info')
log.debug('hello, world')
log.info('hello, world')
log.error('hello, world')
log.critical('hello, world')

Result: Print all log messages to file, and only print log whose level is greater than ERROR to stdout. The log file is located in 'xxx.log' if the module name is xxx.py. The default log file handler is size-rotated, if the log file's size is greater than 20M, then it will be rotated.

Example 2: Use set_logger to change settings

# Change limit size in bytes of default rotating action
log.set_logger(limit = 10240) # 10M

# Use time-rotated file handler, each day has a different log file, see
# logging.handlers.TimedRotatingFileHandler for more help about 'when'
log.set_logger(when = 'D', limit = 1)

# Use normal file handler (not rotated)
log.set_logger(backup_count = 0)

# File log level set to INFO, and stdout log level set to DEBUG
log.set_logger(cmdlevel = 'DEBUG', filelevel = 'INFO')

# Change default log file name and log mode
log.set_logger(filename = 'yyy.log', mode = 'w')

# Change default log formatter
log.set_logger(cmdfmt = '[%(levelname)s] %(message)s')

python_log's People

Contributors

huangming avatar

Watchers

 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.