Skip to main content

Store you operation log to different backend.

Project description

Project icon

Loggage: Code Less, Make More

Introduction

Loggage allow you to store operation log in defferent locations, such as MySQL, Redis, Influxdb, Elasticsearch, and more.

Installation

  1. Install uv (A fast Python package installer and resolver):
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Clone the repository:
git clone https://github.com/jience/loggage.git
cd loggage
  1. Create a new virtual environment and activate it:
uv venv
source .venv/bin/activate  # On Unix/macOS
# Or on Windows:
# .venv\Scripts\activate
  1. Install dependencies:
uv pip install -r requirements.txt

Configuration

Follow these steps to set up your configuration:

  1. Create a config.yaml file in the config directory (you can copy from the example):
cp config/config.example.yaml config/config.yaml
  1. Edit config/config.yaml to customize settings:
default_storage: mysql
storages:
  mysql:
    enabled: true
    host: localhost
    port: 3306
    user: user
    password: password
    db: db_name
    table: operation_log
    pool_size: 20
    max_overflow: 5

  elasticsearch:
    enabled: true
    hosts: ["http://localhost:9200"]
    index: operation-log
    timeout: 30

  redis:
    enabled: false
    host: localhost
    port: 6379
    stream_key: operation_log

Quick Start

One line for run:

python main.py

Usage

import asyncio
import uuid
from datetime import datetime

from src.core.logger import OperationLogger
from src.core.models import OperationLog, LogDetailItem
from src.utils.config import load_config


async def main():
    config = load_config("config/config.yaml")
    operation_logger = OperationLogger(config)
    await operation_logger.initialize()

    log_detail = LogDetailItem(id=uuid.uuid4().hex, name="vdi", type="admin")
    log_data = OperationLog(
        request_id=uuid.uuid4().hex,
        user_id=uuid.uuid4().hex,
        user_name="vdi",
        obj_id=uuid.uuid4().hex,
        obj_name="Arclient-W",
        ref_id=uuid.uuid4().hex,
        ref_name="abc",
        resource_type="user",
        operation_type="business",
        action="login",
        status="success",
        detail=[log_detail],
        request_ip="127.0.0.1",
        request_params="{}",
        interval_time=0,
        error_code="",
        error_message="",
        extra="{}",
        response_body="{}",
        created_at=datetime.now(),
        updated_at=datetime.now(),
    )

    try:
        await operation_logger.log(log_data)
    finally:
        await operation_logger.close()


if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loggage-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loggage-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file loggage-0.1.0.tar.gz.

File metadata

  • Download URL: loggage-0.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.1

File hashes

Hashes for loggage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5db4f7758182733273d07b749b6973aae93602457cc8b076bde38dc8ddd3b74c
MD5 159cb3b5792a298c3ea689e66000ae9a
BLAKE2b-256 63b1e9a2b1ed574738f8726bd4ded37d2d959b3382ab98e7228659f2e2064d7c

See more details on using hashes here.

File details

Details for the file loggage-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: loggage-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.1

File hashes

Hashes for loggage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13a6ac6040cf95075771a75080d969190ba3afbbedda24002529b407ed137a66
MD5 891bc86648aba9da8615884eed2fd7ee
BLAKE2b-256 2cf674699864811d2420ad117327575aca3745ca7eafa37d09a90172c585804d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page