Skip to main content

Simple configuration allows log output to console, file, database at the same time

Project description


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

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

第一步: 安装模块



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 


The second is installed through git repository source code.

pip3 install git+

第二步: 使用模块

Quick start

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

After installing the cpxlog package, a default configuration file named, 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 import the config demo class

# load config information from class
# ... 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")"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  


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

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

⚠️ Refer to the “” 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                        |
    ....                         |

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pcpxlog, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size pcpxlog-0.1-py3-none-any.whl (16.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pcpxlog-0.1.tar.gz (12.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page