Code Monkey home page Code Monkey logo

pcpxlog's Introduction

PCPXlog

Python版-复合日志模块, 通过简单的配置即可以将日志同时输出到控制台、文件、数据库等.

Python version of the composite log module, through simple configuration, can output the log to the console, file, database at the same time.


第一步: 安装模块

Installation

目前你可以通过两种方式安装,推荐使用第一种.

At present, you can install it in two ways. The first one is recommended.

第一种通过pip直接安装, 只需要在终端中输入如下命令即可安装这个模块的最新稳定版本.

The first one is installed directly through pip, and the latest stable version of this module can be installed only by typing the following commands in the terminal.

pip3 install pcpxlog 

第二种通过git仓库源代码安装.

The second is installed through git repository source code.

pip3 install git+https://github.com/kerbalwzy/PCPXlog.git@master

第二步: 使用模块

Quick start

在安装好cpxlog包后可通过在终端中输入命令 “ cpxConfigDemo ” 在当前路径下立即得到一个默认的配置文件, 这个文件的名称叫做 cpxLogConfig.py, 文件详细内容见链接.

After installing the cpxlog package, a default configuration file named cpxLogConfig.py, can be obtained immediately by typing the command "cpxConfigDemo" in the terminal under the current path. The details of the file can be found in the link.

目前我认为cpxlog能被使用到的情况主要有以下两种, 第一种是直接通过CPXLogger获取到logger对象使用, 示例代码如下:

At present, I think there are two main situations in which cpxlog can be used. The first one is to get logger objects directly through CPXLogger. The sample code is as follows:

from pcpxlog import CPXLogger

from cpxLogConfig import CPXLogConfigDemo  
# from the cpxLogConfig.py import the config demo class

# load config information from class
CPXLogger.config_from_class(CPXLogConfigDemo)
# ... also support load config from dict and json file.

# create logger
logger = CPXLogger.create_logger()

# use logger to record log information
logger.debug("This is a test for DEBUG level")
logger.info("This is a test for INFO level")
# ... more log level are supported

第二种是在配合其他框架使用时,将CPXLogger创建的所有hander对象,添加到全局的logger对象中去, 这样让其他框架在运行中保存log信息时也能按照我们给CPXLogger配置的规则保存.

The second is to add all hander objects created by CPXLogger to the global logger object when used with other frameworks, so that other frameworks can save log information in operation according to the rules we configure CPXLogger.

import logging
from pcpxlog import CPXLogger
from cpxLogConfig import CPXLogConfigDemo  

CPXLogger.config_from_class(CPXLogConfigDemo)

# get global_logger
global_logger = logging.getLogger()
# add handler from CPXLogger.handlers
for handler in CPXLogger.handlers:
    global_logger.addHandler(handler)

⚠️ 关于配置文件中的配置信息类该如何去写, 请参考通过命令生成的那个 “cpxLogConfig.py” 文件.

⚠️ Refer to the “cpxLogConfig.py” file generated by the command for how to write the configuration information class in the configuration file.


更多信息和未来发展方向

More and Future

目前这个cpxlog包能帮助我们通过配置,将日志信息输出到控制台, 文件, MongoDB数据库.

未来还希望可以帮助我们将日志信息输出到更多的地方, 例如MySQL, HTTP, Socket 等. 也希望可以通过简单的配置就可以实现在日志信息保存失败时自动发送警告邮件给管理员.

如果你想要加入这个项目中, 请Fork这个项目到你的Git用户, 然后加入你的功能代码, 然后发起一个Pull Requests. 同时为了尽量避免出现多个人想要添加同样功能的问题, 请在Issues中声明提前你想为这个项目贡献什么. 同时也可以在Issues中查看你想添加的功能是否已经有人在做或者已经完成了.

At present, the cpxlog package can help us output log information to console, file and MongoDB database through configuration.

In the future, we hope it can help us output log information to more places, such as MySQL, HTTP, Socket and so on. We also hope it can automatically send warning messages to administrators when log information fails to save through simple configuration.

If you want to join this project, please Fork this project to your Git users, then add your code, and then launch a Pull Requests. At the same time, in order to avoid the problem that many people want to add the same function, please declare in Issues what you want to contribute to this project in advance. Also, you can check in Issues to see if the function you want to add already some people is doing or have finished it.


目前支持的日志输出方式

Supported Present

----------------------------------
CPXLogger Config Handler Support |
----------------------------------
Present:                         |
    console                      |
    file                         |
    rotating_file                |
    rotating_mongodb             |
----------------------------------
Future:                          |
    mysql                        |
    redis                        |
    ....                         |
----------------------------------

pcpxlog's People

Contributors

kerbalwzy avatar lzc978 avatar

Watchers

James Cloos 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.