Skip to content

Repository files navigation

🧾 oh-shit-logger

English | 简体中文

A lightweight error log collection tool written in Go. Aggregate error logs from multiple projects onto a single page, organized by date with pagination, and leverage DeepSeek to automatically analyze error causes — so you can spot and fix issues before your clients even notice.

This project has been parsed by Zread. Click to view an AI-generated project overview.

List Details

✨ Features

  • Centralized Management: Error logs from multiple projects in one place, auto-organized by date
  • AI Analysis: Integrated DeepSeek with streaming output for error diagnosis and fix suggestions
  • Dark Mode: Light / Dark / System three theme options
  • Auto Cleanup: Background task periodically purges expired logs, retention days configurable
  • BasicAuth Protection: Optional HTTP basic authentication to prevent unauthorized access
  • Single Binary Deployment: Compiles to a single executable, copy and run anywhere

🚀 Quick Start

Use Precompiled Binary

Download the latest release from Releases, extract, and run:

chmod +x ./app
./app -port=9999 -retain=7 -user=admin -pass=123123

Visit http://YOUR_SERVER_IP:9999/read to view the log page.

Build from Source

git clone https://github.com/zxc7563598/oh-shit-logger.git
cd oh-shit-logger
go build -o ./app .
./app -port=9999

⚙️ Configuration

Command Line Flags

Flag Description Default
-port Server port 9999
-retain Log retention days 7
-user BasicAuth username -
-pass BasicAuth password -

Warning

BasicAuth is disabled when both -user and -pass are omitted. This is not recommended in production.

DeepSeek API Key

Set it via the "Configure DeepSeek API Key" button in the web UI (only displays a masked version, never exposes the saved key), or manually create config.json:

{
  "api_key": "sk-xxxxxxxxxxxxxxxx"
}

🐘 Using in PHP Projects

We recommend using php-lazylog, a companion PHP Composer library that automatically reports exceptions to oh-shit-logger — no manual integration required.

To integrate manually, format errors as JSON in your exception handler and POST to the /write endpoint:

/**
 * Format a Throwable as a standard JSON string.
 * POST to oh-shit-logger's /write endpoint.
 */
function formatThrowable(Throwable $e, array $context = []): string
{
    $trace = array_map(static function ($t) {
        return [
            'file'     => $t['file'] ?? null,
            'line'     => $t['line'] ?? null,
            'function' => $t['function'] ?? null,
            'class'    => $t['class'] ?? null,
        ];
    }, $e->getTrace());

    return json_encode([
        'uuid'      => bin2hex(random_bytes(8)),
        'project'   => 'your-project-name',
        'level'     => 'error',
        'timestamp' => date('c'),
        'message'   => $e->getMessage(),
        'code'      => $e->getCode(),
        'file'      => $e->getFile(),
        'line'      => $e->getLine(),
        'trace'     => $trace,
        'context'   => (object) $context,
        'server'    => [
            'hostname'    => gethostname() ?: 'unknown',
            'ip'          => $_SERVER['SERVER_ADDR'] ?? '127.0.0.1',
            'php_version' => PHP_VERSION,
        ],
    ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}

// Report the error
$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL        => 'http://YOUR_SERVER_IP:9999/write',
    CURLOPT_POST       => true,
    CURLOPT_POSTFIELDS => formatThrowable($exception, [
        'module' => 'user-center',
        'action' => 'login',
    ]),
    CURLOPT_RETURNTRANSFER => true,
]);
curl_exec($ch);
curl_close($ch);

Note

Only report fatal errors and uncaught exceptions to avoid overwhelming the logs.

📡 API Reference

Method Path Description
POST /write Submit an error log
GET /read?date=2024-01-01&page=1 View logs (Web UI, BasicAuth)
DELETE /delete?uuid=xxx&date=2024-01-01 Delete a log entry
GET /apikey Get API key status (masked, never exposes full key)
POST /apikey Save DeepSeek API Key
POST /chat-stream AI streaming analysis (SSE)

📁 Directory Structure

oh-shit-logger/
├── main.go              # Entry point, route registration
├── config/              # Configuration (CLI flags + config.json)
├── handlers/            # HTTP handlers (write / read / delete / chat / apikey)
├── middleware/           # HTTP middleware (BasicAuth)
├── models/               # Data models
├── storage/              # Log storage (per-date files, JSON Lines)
├── cleanup/              # Background expired log cleanup
├── templates/            # HTML templates
├── static/               # Static assets
└── data/                 # Log data directory (auto-created at runtime)

🤝 Contributing

Issues and suggestions are welcome via GitHub Issues.

If this project helps you, please give it a ⭐️ Star!

About

集中收集多个 PHP 项目的错误日志,按日期分类,支持分页浏览,并接入 DeepSeek AI 自动分析,帮助开发者主动发现和解决问题 | Centrally collect error logs from multiple PHP projects, categorize them by date, support paginated browsing, and integrate DeepSeek AI for automatic analysis to help developers proactively identify and resolve issues

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages