op-log


Nameop-log JSON
Version 0.21.0 PyPI version JSON
download
home_page
SummaryEasy-to-use context-rich Python logging library.
upload_time2023-09-28 22:18:00
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMIT License Copyright (c) 2023 Ori Bar-ilan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords oplog logging logger
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- Top Section -->
<p align="center">
  <a href="https://oribarilan.github.io/oplog"><img src="https://oribarilan.github.io/oplog/imgs/logo_full.png" alt="oplog logo"></a>
</p>

<p align="center">
  <b>Easy-to-use context-rich Python logging library.</b>
</p>

<!-- Badges using https://shields.io/badges/ -->
<p align="center">
  <!-- Python versions -->
  <a href="https://www.python.org/downloads/">
    <img src="https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11-blue" alt="python versions">
  </a>
  <!-- Downloads -->
  <a href="https://pypi.org/project/op-log/">
    <img src="https://img.shields.io/pypi/dm/op-log?link=https%3A%2F%2Fpypi.org%2Fproject%2Fop-log%2F" alt="downloads">
  </a>
  <!-- Ruff credit -->
  <a href="https://github.com/astral-sh/ruff">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
  </a>
  <!-- Build -->
  <a href="https://github.com/oribarilan/oplog/actions/workflows/package_build.yml">
    <img src="https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/package_build.yml" alt="build">
  </a>
  <!-- Lint -->
  <a href="https://github.com/oribarilan/oplog/actions/workflows/lint.yml">
    <img src="https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/lint.yml?label=lint" alt="lint">
  </a>
  <!-- Coverage -->
  <a href="https://github.com/oribarilan/oplog/actions/workflows/coverage.yml">
    <img src="https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/coverage.yml?label=coverage%3E95%25" alt="coverage">
  </a>
  <!-- Security -->
  <a href="https://github.com/oribarilan/oplog/actions/workflows/security_check.yml">
    <img src="https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/security_check.yml?label=security" alt="security">
  </a>
</p>

<hr>

Full documentation: [oribarilan.github.io/oplog](https://oribarilan.github.io/oplog/).

Source code: [github.com/oribarilan/oplog](http://www.github.com/oribarilan/oplog/).

---

## Installation
You can install oplog from PyPI using pip:
```bash
pip install op-log
```

## What is oplog?

oplog is a modern logging library for Python application.
oplog offers a different paradigm for logging, which is based on the concept of logging operations.
Instead of creating a "log-book", which is a long scroll of text messages, oplog is about logging operations with rich data.

Please refer to our full documentation at [oribarilan.github.io/oplog](https://oribarilan.github.io/oplog/).

### Key features

1. **Object Oriented**: Intuitive API, easy to use and extend.
2. **Modern & Scalable**: Unlike log messages, oplog is scaleable. Ingesting oplogs to a columnar database allows you to query, analyze and monitor your app in a modern and performant way.
3. **Standardized**: No more mess and inconsistency across your logs. oplog creates a standard for how logs should be written across your code base. Clean code, clean logs.
4. **Production Ready**: Easily create dashboards and monitors on top of logged data.
5. **Lightweight**: oplog is a layer on top of the standard Python logging library. It is easy to integrate and use.
6. **Minimal**: While oplog is rich with metadata, you only log what you need. Creating smaller and more efficient logs.

## Getting Started

### Setting up the logger

oplog naturally extends Python's built-in logger. 
To start, create an `OperationHandler`, and attach to it any  logging handler of your choice. Additionally, you should customize your output log format with a formatter. You can create your own or use a built-in one (such as  `VerboseOpLogLineFormatter`).

``` py linenums="1" title="Setting up the logger" hl_lines="5 6 7 8"
import logging
from oplog import Operated, OperationHandler
from oplog.formatters import VerboseOplogLineFormatter

stream_op_handler = OperationHandler(
    handler=logging.StreamHandler(), # <-- any logging handler
    formatter=VerboseOplogLineFormatter(), # <-- custom formatter or built-in ones
)   
logging.basicConfig(level=logging.INFO, handlers=[stream_op_handler])

# using a decorator, for simplicity
@Operated()
def foo():
    pass
    
foo()
```

Output:
``` title="Output"
2023-08-31 17:31:08.519900 (0ms): [foo.foo / Success]
```

As you can see, you can use any handler, formatter and filter you want. Oplog does not interfere with them.

* Line 6 (highlighted) makes any handler an "Operation Handler". If you want to also handle log-book-style logs, you can keep your existing handler (for log message, like `logger.info("This is a conventional log message")`).
* Line 7 (highlighted) decides on the log format. It is using a built-in formatter, but you can create your own formatter easily.

### Using Context Managers

For more control, you can use the context manager syntax. This allows, for example, to add custom properties to the operation.

``` py linenums="1" title="Logging operations using the context manager" hl_lines="13 1"
import logging
from oplog import Operation, OperationHandler
from oplog.formatters import VerboseOplogLineFormatter

stream_op_handler = OperationHandler(
    handler=logging.StreamHandler(), # <-- any logging handler
    formatter=VerboseOplogLineFormatter(), # <-- custom formatter or built-in ones
)   
logging.basicConfig(level=logging.INFO, handlers=[stream_op_handler])

# using a context manager, for more control
def bar():
    with Operation(name="my_operation") as op:
        op.add("metric", 5)
        pass
    
bar()
```

Output:
``` title="Output"
2023-08-31 17:41:09.088966 (0ms): [my_operation / Success] {'metric': 5}
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "op-log",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "oplog,logging,logger",
    "author": "",
    "author_email": "Ori Bar-ilan <python.oplog@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1d/fc/7c33d5c3bf492aa38d116140bc15e5879e7145ace0145a4462ae1a03971c/op-log-0.21.0.tar.gz",
    "platform": null,
    "description": "<!-- Top Section -->\n<p align=\"center\">\n  <a href=\"https://oribarilan.github.io/oplog\"><img src=\"https://oribarilan.github.io/oplog/imgs/logo_full.png\" alt=\"oplog logo\"></a>\n</p>\n\n<p align=\"center\">\n  <b>Easy-to-use context-rich Python logging library.</b>\n</p>\n\n<!-- Badges using https://shields.io/badges/ -->\n<p align=\"center\">\n  <!-- Python versions -->\n  <a href=\"https://www.python.org/downloads/\">\n    <img src=\"https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11-blue\" alt=\"python versions\">\n  </a>\n  <!-- Downloads -->\n  <a href=\"https://pypi.org/project/op-log/\">\n    <img src=\"https://img.shields.io/pypi/dm/op-log?link=https%3A%2F%2Fpypi.org%2Fproject%2Fop-log%2F\" alt=\"downloads\">\n  </a>\n  <!-- Ruff credit -->\n  <a href=\"https://github.com/astral-sh/ruff\">\n    <img src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\" alt=\"Ruff\">\n  </a>\n  <!-- Build -->\n  <a href=\"https://github.com/oribarilan/oplog/actions/workflows/package_build.yml\">\n    <img src=\"https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/package_build.yml\" alt=\"build\">\n  </a>\n  <!-- Lint -->\n  <a href=\"https://github.com/oribarilan/oplog/actions/workflows/lint.yml\">\n    <img src=\"https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/lint.yml?label=lint\" alt=\"lint\">\n  </a>\n  <!-- Coverage -->\n  <a href=\"https://github.com/oribarilan/oplog/actions/workflows/coverage.yml\">\n    <img src=\"https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/coverage.yml?label=coverage%3E95%25\" alt=\"coverage\">\n  </a>\n  <!-- Security -->\n  <a href=\"https://github.com/oribarilan/oplog/actions/workflows/security_check.yml\">\n    <img src=\"https://img.shields.io/github/actions/workflow/status/oribarilan/oplog/security_check.yml?label=security\" alt=\"security\">\n  </a>\n</p>\n\n<hr>\n\nFull documentation: [oribarilan.github.io/oplog](https://oribarilan.github.io/oplog/).\n\nSource code: [github.com/oribarilan/oplog](http://www.github.com/oribarilan/oplog/).\n\n---\n\n## Installation\nYou can install oplog from PyPI using pip:\n```bash\npip install op-log\n```\n\n## What is oplog?\n\noplog is a modern logging library for Python application.\noplog offers a different paradigm for logging, which is based on the concept of logging operations.\nInstead of creating a \"log-book\", which is a long scroll of text messages, oplog is about logging operations with rich data.\n\nPlease refer to our full documentation at [oribarilan.github.io/oplog](https://oribarilan.github.io/oplog/).\n\n### Key features\n\n1. **Object Oriented**: Intuitive API, easy to use and extend.\n2. **Modern & Scalable**: Unlike log messages, oplog is scaleable. Ingesting oplogs to a columnar database allows you to query, analyze and monitor your app in a modern and performant way.\n3. **Standardized**: No more mess and inconsistency across your logs. oplog creates a standard for how logs should be written across your code base. Clean code, clean logs.\n4. **Production Ready**: Easily create dashboards and monitors on top of logged data.\n5. **Lightweight**: oplog is a layer on top of the standard Python logging library. It is easy to integrate and use.\n6. **Minimal**: While oplog is rich with metadata, you only log what you need. Creating smaller and more efficient logs.\n\n## Getting Started\n\n### Setting up the logger\n\noplog naturally extends Python's built-in logger. \nTo start, create an `OperationHandler`, and attach to it any  logging handler of your choice. Additionally, you should customize your output log format with a formatter. You can create your own or use a built-in one (such as  `VerboseOpLogLineFormatter`).\n\n``` py linenums=\"1\" title=\"Setting up the logger\" hl_lines=\"5 6 7 8\"\nimport logging\nfrom oplog import Operated, OperationHandler\nfrom oplog.formatters import VerboseOplogLineFormatter\n\nstream_op_handler = OperationHandler(\n    handler=logging.StreamHandler(), # <-- any logging handler\n    formatter=VerboseOplogLineFormatter(), # <-- custom formatter or built-in ones\n)   \nlogging.basicConfig(level=logging.INFO, handlers=[stream_op_handler])\n\n# using a decorator, for simplicity\n@Operated()\ndef foo():\n    pass\n    \nfoo()\n```\n\nOutput:\n``` title=\"Output\"\n2023-08-31 17:31:08.519900 (0ms): [foo.foo / Success]\n```\n\nAs you can see, you can use any handler, formatter and filter you want. Oplog does not interfere with them.\n\n* Line 6 (highlighted) makes any handler an \"Operation Handler\". If you want to also handle log-book-style logs, you can keep your existing handler (for log message, like `logger.info(\"This is a conventional log message\")`).\n* Line 7 (highlighted) decides on the log format. It is using a built-in formatter, but you can create your own formatter easily.\n\n### Using Context Managers\n\nFor more control, you can use the context manager syntax. This allows, for example, to add custom properties to the operation.\n\n``` py linenums=\"1\" title=\"Logging operations using the context manager\" hl_lines=\"13 1\"\nimport logging\nfrom oplog import Operation, OperationHandler\nfrom oplog.formatters import VerboseOplogLineFormatter\n\nstream_op_handler = OperationHandler(\n    handler=logging.StreamHandler(), # <-- any logging handler\n    formatter=VerboseOplogLineFormatter(), # <-- custom formatter or built-in ones\n)   \nlogging.basicConfig(level=logging.INFO, handlers=[stream_op_handler])\n\n# using a context manager, for more control\ndef bar():\n    with Operation(name=\"my_operation\") as op:\n        op.add(\"metric\", 5)\n        pass\n    \nbar()\n```\n\nOutput:\n``` title=\"Output\"\n2023-08-31 17:41:09.088966 (0ms): [my_operation / Success] {'metric': 5}\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Ori Bar-ilan  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Easy-to-use context-rich Python logging library.",
    "version": "0.21.0",
    "project_urls": {
        "Homepage": "https://github.com/oribarilan/oplog"
    },
    "split_keywords": [
        "oplog",
        "logging",
        "logger"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e2db2f6f7b3d15a9dc5a8ae4bba4dda62d9ecc478dbbe0414ea69693107573f3",
                "md5": "fa957079de0a9d07aa97dddc85e43878",
                "sha256": "c555587427ca5f4cb64601483b5c7797d35679043d4a80aa8b6f7f81225ef13b"
            },
            "downloads": -1,
            "filename": "op_log-0.21.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fa957079de0a9d07aa97dddc85e43878",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 20725,
            "upload_time": "2023-09-28T22:17:58",
            "upload_time_iso_8601": "2023-09-28T22:17:58.737903Z",
            "url": "https://files.pythonhosted.org/packages/e2/db/2f6f7b3d15a9dc5a8ae4bba4dda62d9ecc478dbbe0414ea69693107573f3/op_log-0.21.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1dfc7c33d5c3bf492aa38d116140bc15e5879e7145ace0145a4462ae1a03971c",
                "md5": "6fabe4a3cd90d529ca65b99cbe5cdd85",
                "sha256": "96004dbdeafb4cc169a88bd9d9650312894f3fce6690cd43599883b6dd280fdf"
            },
            "downloads": -1,
            "filename": "op-log-0.21.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6fabe4a3cd90d529ca65b99cbe5cdd85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 1857785,
            "upload_time": "2023-09-28T22:18:00",
            "upload_time_iso_8601": "2023-09-28T22:18:00.618716Z",
            "url": "https://files.pythonhosted.org/packages/1d/fc/7c33d5c3bf492aa38d116140bc15e5879e7145ace0145a4462ae1a03971c/op-log-0.21.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-28 22:18:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "oribarilan",
    "github_project": "oplog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "op-log"
}
        
Elapsed time: 0.53359s