cnblogger


Namecnblogger JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryConfigurable logger that writes to CLI, file, HTTP API, and optional databases via simple JSON config.
upload_time2025-08-13 17:38:28
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords logging logger cli file api database sqlite mysql postgres mongodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
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

```python
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`.

Config location:
- By default: put `cnblogger.config` in the app's current working directory (CWD).
- Env override:
```bash
export CNBLOGGER_CONFIG=/path/to/cnblogger.config
```
- Code override:
```python
from cnblogger import CNBLogger
logger = CNBLogger(config_path="/path/to/cnblogger.config")
```

Create or edit a `cnblogger.config` JSON file in your project root (or set `CNBLOGGER_CONFIG` env var to a path). Example with databases:

```json
{
  "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). If `file_same_day_mode` is `new`, files are `yyyymmdd_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|message` or in columns.
- API verify: Set `api_verify` to `true`/`false` or a CA bundle path. Protocol is inferred from `api_url`.
- Databases:
  - SQLite: set `db_sqlite_path` and optional `db_sqlite_table`.
  - MySQL: set `db_mysql` object with connection details and `table`.
  - Postgres: set `db_postgres` object; optional `sslmode`.
  - MongoDB: set `db_mongo_uri`, `db_mongo_database`, `db_mongo_collection`.

### Types
The package is typed (`py.typed`). All public APIs include type hints.

### License
MIT - See the [LICENSE](LICENSE) file.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cnblogger",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "logging, logger, cli, file, api, database, sqlite, mysql, postgres, mongodb",
    "author": null,
    "author_email": "\"Mr. Clark\" <geoff@cnb.llc>",
    "download_url": "https://files.pythonhosted.org/packages/6c/42/258f61a3f5df8b1a7d354b45fc7f869167aeeefdc10fcf28f11bab3a535a/cnblogger-0.2.1.tar.gz",
    "platform": null,
    "description": "# cnblogger\n\nConfigurable, typed Python logger that can write to CLI, file, HTTP API, and databases. Controlled by a simple JSON config file `cnblogger.config`.\n\n- Repository: https://github.com/AznIronMan/cnblogger\n\n## Installation\n\n```bash\npip install cnblogger                 # base (no optional deps)\npip install \"cnblogger[colors]\"      # CLI colors via colorama\npip install \"cnblogger[api]\"         # HTTP API sink via requests\npip install \"cnblogger[sqlite]\"      # SQLite (built-in stdlib, extras not required)\npip install \"cnblogger[mysql]\"       # MySQL via PyMySQL\npip install \"cnblogger[postgres]\"    # PostgreSQL via psycopg2-binary\npip install \"cnblogger[mongo]\"       # MongoDB via pymongo\npip install \"cnblogger[all]\"         # everything\n```\n\n## Usage\n\n```python\nfrom cnblogger import CNBLogger\n\nlogger = CNBLogger()  # auto-loads ./cnblogger.config if present\nlogger.info(\"App started\")\nlogger.error(\"Something went wrong\")\n```\n\n### Configuration\nIf `cnblogger.config` does not exist, it will be created automatically with defaults on first use. You can also copy from `cnblogger.config.example`.\n\nConfig location:\n- By default: put `cnblogger.config` in the app's current working directory (CWD).\n- Env override:\n```bash\nexport CNBLOGGER_CONFIG=/path/to/cnblogger.config\n```\n- Code override:\n```python\nfrom cnblogger import CNBLogger\nlogger = CNBLogger(config_path=\"/path/to/cnblogger.config\")\n```\n\nCreate or edit a `cnblogger.config` JSON file in your project root (or set `CNBLOGGER_CONFIG` env var to a path). Example with databases:\n\n```json\n{\n  \"mode\": \"all\",\n  \"delimiter\": \"|\",\n  \"file_dir\": \"./.logs\",\n  \"file_same_day_mode\": \"append\",\n  \"api_url\": \"https://log.example.com/ingest\",\n  \"api_verify\": true,\n  \"api_timeout_seconds\": 3.0,\n  \"api_headers\": {\"Authorization\": \"Bearer <token>\"},\n  \"db_sqlite_path\": \"./.logs/logs.db\",\n  \"db_sqlite_table\": \"logs\",\n  \"db_mysql\": {\"host\": \"localhost\", \"port\": 3306, \"user\": \"root\", \"password\": \"\", \"database\": \"logs\", \"table\": \"logs\"},\n  \"db_postgres\": {\"host\": \"localhost\", \"port\": 5432, \"user\": \"postgres\", \"password\": \"\", \"database\": \"logs\", \"table\": \"logs\", \"sslmode\": \"prefer\"},\n  \"db_mongo_uri\": \"mongodb://localhost:27017\",\n  \"db_mongo_database\": \"logs\",\n  \"db_mongo_collection\": \"entries\",\n  \"colors\": {\"INFO\": \"cyan\", \"CRITICAL\": \"red\", \"ERROR\": \"bright_yellow\", \"WARN\": \"yellow\", \"DEBUG\": \"blue\"},\n  \"timestamp_utc\": false\n}\n```\n\n- mode: `cli` | `file` | `api` | `both` (cli+file) | `all` (cli+file+api). Default: `cli`.\n- file names: `yyyymmdd.log` (append by default on same day). If `file_same_day_mode` is `new`, files are `yyyymmdd_HHMMSS.log`.\n- CLI format: `[yyyy.mm.dd hh:mm:ss.mmm] [LEVEL] message` (LEVEL colored, colors configurable).\n- File/API/DB format stored consistently as `ts|LEVEL|message` or in columns.\n- API verify: Set `api_verify` to `true`/`false` or a CA bundle path. Protocol is inferred from `api_url`.\n- Databases:\n  - SQLite: set `db_sqlite_path` and optional `db_sqlite_table`.\n  - MySQL: set `db_mysql` object with connection details and `table`.\n  - Postgres: set `db_postgres` object; optional `sslmode`.\n  - MongoDB: set `db_mongo_uri`, `db_mongo_database`, `db_mongo_collection`.\n\n### Types\nThe package is typed (`py.typed`). All public APIs include type hints.\n\n### License\nMIT - See the [LICENSE](LICENSE) file.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Configurable logger that writes to CLI, file, HTTP API, and optional databases via simple JSON config.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/AznIronMan/cnblogger",
        "Repository": "https://github.com/AznIronMan/cnblogger.git"
    },
    "split_keywords": [
        "logging",
        " logger",
        " cli",
        " file",
        " api",
        " database",
        " sqlite",
        " mysql",
        " postgres",
        " mongodb"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0959f12612572e6a94573de41d1c376035ba66cadacf9c75bc0a922b304576b2",
                "md5": "329f614c1189482028acd0e06977279b",
                "sha256": "6f97b749c3ecef788130323a2819d1064f63d3ec1bc64aee6fa8a81f6ac1358c"
            },
            "downloads": -1,
            "filename": "cnblogger-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "329f614c1189482028acd0e06977279b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10454,
            "upload_time": "2025-08-13T17:38:26",
            "upload_time_iso_8601": "2025-08-13T17:38:26.767944Z",
            "url": "https://files.pythonhosted.org/packages/09/59/f12612572e6a94573de41d1c376035ba66cadacf9c75bc0a922b304576b2/cnblogger-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6c42258f61a3f5df8b1a7d354b45fc7f869167aeeefdc10fcf28f11bab3a535a",
                "md5": "6d97dd1b98158561a22fe8bd767a2aca",
                "sha256": "d16139989fd9637c27f9e2714f1bdcceaebf0850851ee499087cdf8695a55ced"
            },
            "downloads": -1,
            "filename": "cnblogger-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6d97dd1b98158561a22fe8bd767a2aca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10372,
            "upload_time": "2025-08-13T17:38:28",
            "upload_time_iso_8601": "2025-08-13T17:38:28.085766Z",
            "url": "https://files.pythonhosted.org/packages/6c/42/258f61a3f5df8b1a7d354b45fc7f869167aeeefdc10fcf28f11bab3a535a/cnblogger-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-13 17:38:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AznIronMan",
    "github_project": "cnblogger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cnblogger"
}
        
Elapsed time: 1.15724s