tracebook


Nametracebook JSON
Version 0.1.10 PyPI version JSON
download
home_pageNone
SummaryA comprehensive code bookkeeping package
upload_time2024-08-14 14:13:11
maintainerNone
docs_urlNone
authorSujal Choudhari
requires_python>=3.6
licenseNone
keywords book-keeping visualizer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Trace Book

**Trace Book** is a Python package designed for comprehensive code bookkeeping. It provides tools to log function calls, parameters, return values, and execution times. Additionally, it supports decorators for easy integration, automatic error tracking, and remote log transmission, all with customizable log levels and output configurations.

![UI](https://raw.githubusercontent.com/SujalChoudhari/TraceBook/main/example/example-ui.png)

## Features

- **Function Logging**: Track function calls, parameters, return values, and execution times.
- **Automatic Error Tracking**: Log exceptions and stack traces automatically.
- **Decorators**: Simplify logging with decorators that track function parameters and results.
- **Remote Log Transmission**: Securely send logs to a remote server.
- **Customizable Log Levels**: Control log verbosity with DEBUG, INFO, WARNING, and ERROR levels.
- **Configurable Output**: Choose between logging to console, files, or transmitting logs to a remote server.
- **Web UI**: Visualize logs and system performance metrics through a customizable dashboard.

## Installation

You can install **Trace Book** using `pip`:

```bash
pip install tracebook
```

Or by cloning the repository and installing it manually:

```bash
git clone https://github.com/yourusername/tracebook.git
cd tracebook
pip install .
```

## Usage

### Basic Logging

```python
from tracebook import Logger
from tracebook.config import Config, LogLevel

logger = Logger(config=Config(log_level=LogLevel.INFO, output="both", file_path="app.log"))

@logger.trace()
def add(a, b):
    return a + b

result = add(3, 5)
print(f"Result: {result}")
```

### Logging with Resource Tracking

```python
@logger.trace(log_resources=True)
def compute_factorial(n):
    if n == 0:
        return 1
    return n * compute_factorial(n - 1)

compute_factorial(5)
```

### Using Different Log Levels

```python
logger.debug("Debugging information")
logger.info("General information")
logger.warning("Warning: resource running low")
logger.error("Error occurred: unable to connect")
logger.critical("Critical: system shutdown imminent")
```

### Exception Handling

```python
@logger.trace()
def divide(a, b):
    return a / b

try:
    divide(10, 0)
except ZeroDivisionError:
    logger.error("Attempted division by zero")
```

### Remote Logging Configuration

```python{7,10}
from tracebook.config import RemoteConfig

remote_logger = Logger(
    config=Config(
        log_level=LogLevel.INFO,
        output="file",
        remote_config=RemoteConfig(
            url="https://logs.example.com",
            headers={"Authorization": "Bearer your-token"}
        )
    )
)

@remote_logger.trace()
def important_function():
    # Function logic here
    pass
```

Internally teacebook will do a `POST` call to your server with the file as the payload.

```sh
curl -X POST "http://example.com/upload" \
     -H "Content-Type: multipart/form-data" \
     -H "Authorization: Bearer your_token_here" \
     -F "file=@/path/to/your/logfile.log"
```

### Web UI Configuration

```python
from tracebook.config import WebUIConfig

web_logger = Logger(
    config=Config(
        log_level=LogLevel.INFO,
        output="both",
        web_config=WebUIConfig(
            title="My TraceBook Dashboard",
            foreground_color="#123456",
            background_color="#F0F0F0",
            show_star_on_github=True,
            indent_logs=True,
            is_active=True,
            port=2234,
            refresh_interval=2000,
            max_data_points=200,

        )
    )
)

@web_logger.trace()
def monitor_system():
    # Function logic here
    pass
```

### Configuring Log Levels and Output

Control the verbosity of logs by setting the log level and choosing the output:

```python
from tracebook import Logger
from tracebook.config import Config, LogLevel

logger = Logger(
    config=Config(
        log_level=LogLevel.DEBUG,
        output="both",
        file_path="logs.txt"
    )
)

@logger.trace(log_resources=True)
def my_function(param1, param2):
    return param1 + param2

my_function(1, 2)
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tracebook",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "book-keeping, visualizer",
    "author": "Sujal Choudhari",
    "author_email": "hello@sujal.xyz",
    "download_url": "https://files.pythonhosted.org/packages/e1/f1/39acbbfe5afb93633c5456b69cb98528d0834fd62eadef7570146539ee48/tracebook-0.1.10.tar.gz",
    "platform": null,
    "description": "# Trace Book\r\n\r\n**Trace Book** is a Python package designed for comprehensive code bookkeeping. It provides tools to log function calls, parameters, return values, and execution times. Additionally, it supports decorators for easy integration, automatic error tracking, and remote log transmission, all with customizable log levels and output configurations.\r\n\r\n![UI](https://raw.githubusercontent.com/SujalChoudhari/TraceBook/main/example/example-ui.png)\r\n\r\n## Features\r\n\r\n- **Function Logging**: Track function calls, parameters, return values, and execution times.\r\n- **Automatic Error Tracking**: Log exceptions and stack traces automatically.\r\n- **Decorators**: Simplify logging with decorators that track function parameters and results.\r\n- **Remote Log Transmission**: Securely send logs to a remote server.\r\n- **Customizable Log Levels**: Control log verbosity with DEBUG, INFO, WARNING, and ERROR levels.\r\n- **Configurable Output**: Choose between logging to console, files, or transmitting logs to a remote server.\r\n- **Web UI**: Visualize logs and system performance metrics through a customizable dashboard.\r\n\r\n## Installation\r\n\r\nYou can install **Trace Book** using `pip`:\r\n\r\n```bash\r\npip install tracebook\r\n```\r\n\r\nOr by cloning the repository and installing it manually:\r\n\r\n```bash\r\ngit clone https://github.com/yourusername/tracebook.git\r\ncd tracebook\r\npip install .\r\n```\r\n\r\n## Usage\r\n\r\n### Basic Logging\r\n\r\n```python\r\nfrom tracebook import Logger\r\nfrom tracebook.config import Config, LogLevel\r\n\r\nlogger = Logger(config=Config(log_level=LogLevel.INFO, output=\"both\", file_path=\"app.log\"))\r\n\r\n@logger.trace()\r\ndef add(a, b):\r\n    return a + b\r\n\r\nresult = add(3, 5)\r\nprint(f\"Result: {result}\")\r\n```\r\n\r\n### Logging with Resource Tracking\r\n\r\n```python\r\n@logger.trace(log_resources=True)\r\ndef compute_factorial(n):\r\n    if n == 0:\r\n        return 1\r\n    return n * compute_factorial(n - 1)\r\n\r\ncompute_factorial(5)\r\n```\r\n\r\n### Using Different Log Levels\r\n\r\n```python\r\nlogger.debug(\"Debugging information\")\r\nlogger.info(\"General information\")\r\nlogger.warning(\"Warning: resource running low\")\r\nlogger.error(\"Error occurred: unable to connect\")\r\nlogger.critical(\"Critical: system shutdown imminent\")\r\n```\r\n\r\n### Exception Handling\r\n\r\n```python\r\n@logger.trace()\r\ndef divide(a, b):\r\n    return a / b\r\n\r\ntry:\r\n    divide(10, 0)\r\nexcept ZeroDivisionError:\r\n    logger.error(\"Attempted division by zero\")\r\n```\r\n\r\n### Remote Logging Configuration\r\n\r\n```python{7,10}\r\nfrom tracebook.config import RemoteConfig\r\n\r\nremote_logger = Logger(\r\n    config=Config(\r\n        log_level=LogLevel.INFO,\r\n        output=\"file\",\r\n        remote_config=RemoteConfig(\r\n            url=\"https://logs.example.com\",\r\n            headers={\"Authorization\": \"Bearer your-token\"}\r\n        )\r\n    )\r\n)\r\n\r\n@remote_logger.trace()\r\ndef important_function():\r\n    # Function logic here\r\n    pass\r\n```\r\n\r\nInternally teacebook will do a `POST` call to your server with the file as the payload.\r\n\r\n```sh\r\ncurl -X POST \"http://example.com/upload\" \\\r\n     -H \"Content-Type: multipart/form-data\" \\\r\n     -H \"Authorization: Bearer your_token_here\" \\\r\n     -F \"file=@/path/to/your/logfile.log\"\r\n```\r\n\r\n### Web UI Configuration\r\n\r\n```python\r\nfrom tracebook.config import WebUIConfig\r\n\r\nweb_logger = Logger(\r\n    config=Config(\r\n        log_level=LogLevel.INFO,\r\n        output=\"both\",\r\n        web_config=WebUIConfig(\r\n            title=\"My TraceBook Dashboard\",\r\n            foreground_color=\"#123456\",\r\n            background_color=\"#F0F0F0\",\r\n            show_star_on_github=True,\r\n            indent_logs=True,\r\n            is_active=True,\r\n            port=2234,\r\n            refresh_interval=2000,\r\n            max_data_points=200,\r\n\r\n        )\r\n    )\r\n)\r\n\r\n@web_logger.trace()\r\ndef monitor_system():\r\n    # Function logic here\r\n    pass\r\n```\r\n\r\n### Configuring Log Levels and Output\r\n\r\nControl the verbosity of logs by setting the log level and choosing the output:\r\n\r\n```python\r\nfrom tracebook import Logger\r\nfrom tracebook.config import Config, LogLevel\r\n\r\nlogger = Logger(\r\n    config=Config(\r\n        log_level=LogLevel.DEBUG,\r\n        output=\"both\",\r\n        file_path=\"logs.txt\"\r\n    )\r\n)\r\n\r\n@logger.trace(log_resources=True)\r\ndef my_function(param1, param2):\r\n    return param1 + param2\r\n\r\nmy_function(1, 2)\r\n```\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A comprehensive code bookkeeping package",
    "version": "0.1.10",
    "project_urls": null,
    "split_keywords": [
        "book-keeping",
        " visualizer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2c2ba2d83685a2d2ee178973cfa8e233c9eb75a620ba230fe60bfa26e4cbd1e",
                "md5": "497d598f4ffe308f9418eac43da3c98b",
                "sha256": "5e4974938822d214d4639b1caf72b40d65ba798ee27fc28183f795cc2da20695"
            },
            "downloads": -1,
            "filename": "tracebook-0.1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "497d598f4ffe308f9418eac43da3c98b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 14421,
            "upload_time": "2024-08-14T14:13:09",
            "upload_time_iso_8601": "2024-08-14T14:13:09.957001Z",
            "url": "https://files.pythonhosted.org/packages/f2/c2/ba2d83685a2d2ee178973cfa8e233c9eb75a620ba230fe60bfa26e4cbd1e/tracebook-0.1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e1f139acbbfe5afb93633c5456b69cb98528d0834fd62eadef7570146539ee48",
                "md5": "8e815da12931a595c342f93069e3224c",
                "sha256": "96668529359282d3d91f96aab25e29cc43305a3d1ec4b26249ec1d5e90bd73aa"
            },
            "downloads": -1,
            "filename": "tracebook-0.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "8e815da12931a595c342f93069e3224c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 15715,
            "upload_time": "2024-08-14T14:13:11",
            "upload_time_iso_8601": "2024-08-14T14:13:11.623615Z",
            "url": "https://files.pythonhosted.org/packages/e1/f1/39acbbfe5afb93633c5456b69cb98528d0834fd62eadef7570146539ee48/tracebook-0.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-14 14:13:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tracebook"
}
        
Elapsed time: 9.83002s