pyla-logger


Namepyla-logger JSON
Version 1.2.1 PyPI version JSON
download
home_pageNone
SummaryStructured logging library for Python applications
upload_time2025-08-07 16:12:08
maintainerNone
docs_urlNone
authorLangAdventure LLC
requires_python>=3.12
licenseGPL-3.0
keywords logging structured-logging python langadventure
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyLa Logger

[![PyPI version](https://badge.fury.io/py/pyla-logger.svg)](https://badge.fury.io/py/pyla-logger)
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

A structured logging library for Python applications that provides JSON-formatted logs with context management and flexible configuration.

## Features

- **Structured JSON Logging**: All logs are output in JSON format with ISO timestamps
- **Context Management**: Add persistent context data that appears in all subsequent log messages
- **Environment-Based Configuration**: Control log levels via environment variables
- **Standard Log Levels**: Support for debug, info, warning, error, and critical levels
- **Exception Logging**: Special handling for exceptions with stack trace information
- **Built on Structlog**: Leverages the powerful and reliable structlog library
- **Ready to Use**: Pre-configured logger instance available for immediate use

## Installation

```bash
pip install pyla-logger
```

## Quick Start

```python
from pyla_logger import logger

# Basic logging
logger.info("Application started")
logger.error("Something went wrong", error_code=500)

# Add persistent context
logger.add_context(user_id="12345", session="abc-def")
logger.info("User action")  # Will include user_id and session in output

# Exception logging
try:
    raise ValueError("Invalid input")
except Exception as e:
    logger.exception(e, "Failed to process request")
```

## Configuration

### Log Levels

Control the minimum log level using the `pyla_logger_level` environment variable:

```bash
export pyla_logger_level=info  # Only info, warning, error, and critical logs will be shown
export pyla_logger_level=error  # Only error and critical logs will be shown
```

Supported levels (case-insensitive):
- `debug` (default)
- `info`  
- `warning`
- `error`
- `critical`

## Usage Examples

### Basic Logging

```python
from pyla_logger import logger

logger.debug("Detailed debug information")
logger.info("General information", component="auth")
logger.warning("Warning message", retry_count=3)
logger.error("Error occurred", error_type="validation")
logger.critical("Critical system failure", system="database")
```

### Context Management

```python
from pyla_logger import logger

# Add context that will appear in all subsequent logs
logger.add_context(
    request_id="req-12345",
    user_id="user-67890",
    environment="production"
)

logger.info("Processing request")  
# Output: {"event": "Processing request", "request_id": "req-12345", "user_id": "user-67890", "environment": "production", "timestamp": "2024-01-01T12:00:00.000000Z", "level": "info"}

logger.error("Request failed", error_code=400)
# Output: {"event": "Request failed", "error_code": 400, "request_id": "req-12345", "user_id": "user-67890", "environment": "production", "timestamp": "2024-01-01T12:00:01.000000Z", "level": "error"}
```

### Exception Logging

```python
from pyla_logger import logger

try:
    result = 10 / 0
except Exception as e:
    logger.exception(e, "Division operation failed", operation="divide", operands=[10, 0])
    # Includes full stack trace and exception details
```

### Advanced Usage

```python
from pyla_logger import logger

# Multiple arguments and keyword arguments
logger.info("User logged in", "additional", "arguments", 
           user_name="john_doe", ip_address="192.168.1.1", success=True)

# Adding context incrementally
logger.add_context(service="auth-service")
logger.add_context(version="1.2.3")  # Adds to existing context

logger.info("Service status check")  # Contains all context data
```

### Creating Custom Logger Instances

```python
from pyla_logger.logger import Logger
import structlog

# Create your own logger instance
custom_logger = Logger(structlog.get_logger("my-service"))
custom_logger.add_context(service="my-service")
custom_logger.info("Custom logger message")
```

## Output Format

All logs are formatted as JSON with the following structure:

```json
{
  "event": "Your log message",
  "level": "info",
  "timestamp": "2024-01-01T12:00:00.000000Z",
  "custom_field": "custom_value",
  "context_field": "context_value"
}
```

## Environment Configuration

Set the log level using environment variables:

```bash
# In your shell or .env file
export pyla_logger_level=warning

# In Docker
ENV pyla_logger_level=info

# In Python code (not recommended, use env vars instead)
import os
os.environ['pyla_logger_level'] = 'error'
```

## Requirements

- Python 3.12+
- structlog >= 25.4.0

## License

This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyla-logger",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "logging, structured-logging, python, langadventure",
    "author": "LangAdventure LLC",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b0/02/a0f618ccf1d746e0c8d20c66b72eb8d535b18b904c6f4890ba0dfdfb3c8a/pyla_logger-1.2.1.tar.gz",
    "platform": null,
    "description": "# PyLa Logger\n\n[![PyPI version](https://badge.fury.io/py/pyla-logger.svg)](https://badge.fury.io/py/pyla-logger)\n[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\nA structured logging library for Python applications that provides JSON-formatted logs with context management and flexible configuration.\n\n## Features\n\n- **Structured JSON Logging**: All logs are output in JSON format with ISO timestamps\n- **Context Management**: Add persistent context data that appears in all subsequent log messages\n- **Environment-Based Configuration**: Control log levels via environment variables\n- **Standard Log Levels**: Support for debug, info, warning, error, and critical levels\n- **Exception Logging**: Special handling for exceptions with stack trace information\n- **Built on Structlog**: Leverages the powerful and reliable structlog library\n- **Ready to Use**: Pre-configured logger instance available for immediate use\n\n## Installation\n\n```bash\npip install pyla-logger\n```\n\n## Quick Start\n\n```python\nfrom pyla_logger import logger\n\n# Basic logging\nlogger.info(\"Application started\")\nlogger.error(\"Something went wrong\", error_code=500)\n\n# Add persistent context\nlogger.add_context(user_id=\"12345\", session=\"abc-def\")\nlogger.info(\"User action\")  # Will include user_id and session in output\n\n# Exception logging\ntry:\n    raise ValueError(\"Invalid input\")\nexcept Exception as e:\n    logger.exception(e, \"Failed to process request\")\n```\n\n## Configuration\n\n### Log Levels\n\nControl the minimum log level using the `pyla_logger_level` environment variable:\n\n```bash\nexport pyla_logger_level=info  # Only info, warning, error, and critical logs will be shown\nexport pyla_logger_level=error  # Only error and critical logs will be shown\n```\n\nSupported levels (case-insensitive):\n- `debug` (default)\n- `info`  \n- `warning`\n- `error`\n- `critical`\n\n## Usage Examples\n\n### Basic Logging\n\n```python\nfrom pyla_logger import logger\n\nlogger.debug(\"Detailed debug information\")\nlogger.info(\"General information\", component=\"auth\")\nlogger.warning(\"Warning message\", retry_count=3)\nlogger.error(\"Error occurred\", error_type=\"validation\")\nlogger.critical(\"Critical system failure\", system=\"database\")\n```\n\n### Context Management\n\n```python\nfrom pyla_logger import logger\n\n# Add context that will appear in all subsequent logs\nlogger.add_context(\n    request_id=\"req-12345\",\n    user_id=\"user-67890\",\n    environment=\"production\"\n)\n\nlogger.info(\"Processing request\")  \n# Output: {\"event\": \"Processing request\", \"request_id\": \"req-12345\", \"user_id\": \"user-67890\", \"environment\": \"production\", \"timestamp\": \"2024-01-01T12:00:00.000000Z\", \"level\": \"info\"}\n\nlogger.error(\"Request failed\", error_code=400)\n# Output: {\"event\": \"Request failed\", \"error_code\": 400, \"request_id\": \"req-12345\", \"user_id\": \"user-67890\", \"environment\": \"production\", \"timestamp\": \"2024-01-01T12:00:01.000000Z\", \"level\": \"error\"}\n```\n\n### Exception Logging\n\n```python\nfrom pyla_logger import logger\n\ntry:\n    result = 10 / 0\nexcept Exception as e:\n    logger.exception(e, \"Division operation failed\", operation=\"divide\", operands=[10, 0])\n    # Includes full stack trace and exception details\n```\n\n### Advanced Usage\n\n```python\nfrom pyla_logger import logger\n\n# Multiple arguments and keyword arguments\nlogger.info(\"User logged in\", \"additional\", \"arguments\", \n           user_name=\"john_doe\", ip_address=\"192.168.1.1\", success=True)\n\n# Adding context incrementally\nlogger.add_context(service=\"auth-service\")\nlogger.add_context(version=\"1.2.3\")  # Adds to existing context\n\nlogger.info(\"Service status check\")  # Contains all context data\n```\n\n### Creating Custom Logger Instances\n\n```python\nfrom pyla_logger.logger import Logger\nimport structlog\n\n# Create your own logger instance\ncustom_logger = Logger(structlog.get_logger(\"my-service\"))\ncustom_logger.add_context(service=\"my-service\")\ncustom_logger.info(\"Custom logger message\")\n```\n\n## Output Format\n\nAll logs are formatted as JSON with the following structure:\n\n```json\n{\n  \"event\": \"Your log message\",\n  \"level\": \"info\",\n  \"timestamp\": \"2024-01-01T12:00:00.000000Z\",\n  \"custom_field\": \"custom_value\",\n  \"context_field\": \"context_value\"\n}\n```\n\n## Environment Configuration\n\nSet the log level using environment variables:\n\n```bash\n# In your shell or .env file\nexport pyla_logger_level=warning\n\n# In Docker\nENV pyla_logger_level=info\n\n# In Python code (not recommended, use env vars instead)\nimport os\nos.environ['pyla_logger_level'] = 'error'\n```\n\n## Requirements\n\n- Python 3.12+\n- structlog >= 25.4.0\n\n## License\n\nThis project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "GPL-3.0",
    "summary": "Structured logging library for Python applications",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://github.com/langadventurellc/pyla-logger",
        "Issues": "https://github.com/langadventurellc/pyla-logger/issues",
        "Repository": "https://github.com/langadventurellc/pyla-logger"
    },
    "split_keywords": [
        "logging",
        " structured-logging",
        " python",
        " langadventure"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "318ca381a39707800ef27f147439be0004951ff24877d63cb758c9090d048e58",
                "md5": "f87ba03f0dd54fe99eee4ce2b783a737",
                "sha256": "407dfb6298e95385a255565c6da68cae6bda917c964ffe9d27426ae7cf02fadc"
            },
            "downloads": -1,
            "filename": "pyla_logger-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f87ba03f0dd54fe99eee4ce2b783a737",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 5768,
            "upload_time": "2025-08-07T16:12:07",
            "upload_time_iso_8601": "2025-08-07T16:12:07.342847Z",
            "url": "https://files.pythonhosted.org/packages/31/8c/a381a39707800ef27f147439be0004951ff24877d63cb758c9090d048e58/pyla_logger-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b002a0f618ccf1d746e0c8d20c66b72eb8d535b18b904c6f4890ba0dfdfb3c8a",
                "md5": "b747a1b0e0405560fd61e4f146a926f3",
                "sha256": "06710f6a17cdf250615e677a1579d9b9411b01a98f3f9c32a756f711fd165d1a"
            },
            "downloads": -1,
            "filename": "pyla_logger-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b747a1b0e0405560fd61e4f146a926f3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 23463,
            "upload_time": "2025-08-07T16:12:08",
            "upload_time_iso_8601": "2025-08-07T16:12:08.331447Z",
            "url": "https://files.pythonhosted.org/packages/b0/02/a0f618ccf1d746e0c8d20c66b72eb8d535b18b904c6f4890ba0dfdfb3c8a/pyla_logger-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-07 16:12:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "langadventurellc",
    "github_project": "pyla-logger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyla-logger"
}
        
Elapsed time: 2.46444s