Configurable logger that writes to CLI, file, HTTP API, and optional databases via simple JSON config.
Project description
cnblogger
Configurable, typed Python logger that can write to CLI, file, HTTP API, and databases. Controlled by a simple JSON config file cnblogger.config.
- Repository: https://github.com/AznIronMan/cnblogger
Installation
pip install cnblogger # base (no optional deps)
pip install "cnblogger[colors]" # CLI colors via colorama
pip install "cnblogger[api]" # HTTP API sink via requests
pip install "cnblogger[sqlite]" # SQLite (built-in stdlib, extras not required)
pip install "cnblogger[mysql]" # MySQL via PyMySQL
pip install "cnblogger[postgres]" # PostgreSQL via psycopg2-binary
pip install "cnblogger[mongo]" # MongoDB via pymongo
pip install "cnblogger[all]" # everything
Usage
from cnblogger import CNBLogger
logger = CNBLogger() # auto-loads ./cnblogger.config if present
logger.info("App started")
logger.error("Something went wrong")
Configuration
If cnblogger.config does not exist, it will be created automatically with defaults on first use. You can also copy from cnblogger.config.example.
Create or edit a cnblogger.config JSON file in your project root (or set CNBLOGGER_CONFIG env var to a path). Example with databases:
{
"mode": "all",
"delimiter": "|",
"file_dir": "./.logs",
"file_same_day_mode": "append",
"api_url": "https://log.example.com/ingest",
"api_verify": true,
"api_timeout_seconds": 3.0,
"api_headers": {"Authorization": "Bearer <token>"},
"db_sqlite_path": "./.logs/logs.db",
"db_sqlite_table": "logs",
"db_mysql": {"host": "localhost", "port": 3306, "user": "root", "password": "", "database": "logs", "table": "logs"},
"db_postgres": {"host": "localhost", "port": 5432, "user": "postgres", "password": "", "database": "logs", "table": "logs", "sslmode": "prefer"},
"db_mongo_uri": "mongodb://localhost:27017",
"db_mongo_database": "logs",
"db_mongo_collection": "entries",
"colors": {"INFO": "cyan", "CRITICAL": "red", "ERROR": "bright_yellow", "WARN": "yellow", "DEBUG": "blue"},
"timestamp_utc": false
}
- mode:
cli|file|api|both(cli+file) |all(cli+file+api). Default:cli. - file names:
yyyymmdd.log(append by default on same day). Iffile_same_day_modeisnew, files areyyyymmdd_HHMMSS.log. - CLI format:
[yyyy.mm.dd hh:mm:ss.mmm] [LEVEL] message(LEVEL colored, colors configurable). - File/API/DB format stored consistently as
ts|LEVEL|messageor in columns. - API verify: Set
api_verifytotrue/falseor a CA bundle path. Protocol is inferred fromapi_url. - Databases:
- SQLite: set
db_sqlite_pathand optionaldb_sqlite_table. - MySQL: set
db_mysqlobject with connection details andtable. - Postgres: set
db_postgresobject; optionalsslmode. - MongoDB: set
db_mongo_uri,db_mongo_database,db_mongo_collection.
- SQLite: set
Types
The package is typed (py.typed). All public APIs include type hints.
License
MIT - See the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cnblogger-0.2.0.tar.gz.
File metadata
- Download URL: cnblogger-0.2.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e158ed0a665ac1a0ea86ddb5bdfa9ad57c2873d2a032bf4cb9e34942337bac11
|
|
| MD5 |
af73901b819da2a4aea671a7b07751b4
|
|
| BLAKE2b-256 |
231e845d9fbbe810677846cdffb885e57fa22f7a2098f36ed152237a9f0f57d5
|
File details
Details for the file cnblogger-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cnblogger-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9631e2cf8c522a7e6682e67d8f772fc9a9e03c9701c138f5ea42a8740fa16998
|
|
| MD5 |
99cd700d3ef545b52dd54651cf6b1868
|
|
| BLAKE2b-256 |
f451324f934a7f6b33c7ab033528d52054867c5dea83efb7597de879be8d33e9
|