sistem log untuk mencatat aplikasi super apps
  • Blade 57.4%
  • PHP 42.3%
  • JavaScript 0.3%
Find a file
2026-07-30 09:29:00 +07:00
api-logger feat: content-based dedupe — skip DataLog if identical response already stored 2026-07-30 09:29:00 +07:00
aplikasi1 feat: Bearer token auth on aplikasi1 & aplikasi2 API 2026-07-30 09:19:46 +07:00
aplikasi2 feat: Bearer token auth on aplikasi1 & aplikasi2 API 2026-07-30 09:19:46 +07:00
.gitignore feat: initial commit — API Logger System v1.0 2026-07-29 15:17:25 +07:00
CATATAN.md feat: Bearer token auth on aplikasi1 & aplikasi2 API 2026-07-30 09:19:46 +07:00
DEVELOPMENT_GUIDE.md feat: initial commit — API Logger System v1.0 2026-07-29 15:17:25 +07:00
PRD.md feat: initial commit — API Logger System v1.0 2026-07-29 15:17:25 +07:00
README.md docs: add troubleshooting — touch utime permission fix 2026-07-29 16:17:22 +07:00
SETUP_INSTRUCTIONS.md feat: initial commit — API Logger System v1.0 2026-07-29 15:17:25 +07:00

API Request Logger System

Sistem terpusat untuk mencatat, memantau, dan mengelola semua request dan response dari API eksternal — dengan Redis deduplication, failed execution guard, dan dashboard real-time.

🚀 Features

  • Request/Response Logging — Catat semua detail request dan response API
  • Redis Deduplication — Cegah duplikasi ApiLog dan DataLog (hash MD5, TTL 5 menit)
  • Failed Execution Guard — Tidak insert DataLog jika status gagal (4xx/5xx/error)
  • Pure JSON Response Data — Render response body sebagai JSON rapi dengan toggle Formatted/Raw
  • Dashboard Cached — Stats + status codes di-cache Redis (5 menit TTL)
  • Rate Limiting — 60 req/menit per user/IP di semua route authenticated
  • API Configuration Management — Daftarkan endpoint, bearer token auto-generate, regenerate
  • CLI Microservicephp artisan datalog:execute {id} [--notif] untuk eksekusi via terminal
  • User Authentication — Role-based access (admin/user), Breeze scaffold
  • User Management — Admin CRUD user (role, status, soft delete)
  • Profile Management — Update profil + change password
  • Audit TrailApiLog (sistem) + DataLog (manual) terpisah

📋 Tech Stack

Layer Tech
Backend Laravel 13 (PHP 8.5+)
Database MariaDB 10.5+
Cache Redis 6.0+
Frontend Blade + Tailwind CSS + Alpine.js
HTTP Client Guzzle HTTP
Server Caddy v2 + PHP-FPM 8.5

🏗️ Arsitektur

┌──────────────────────────────────────────────────────────────┐
│                  API Logger Dashboard                          │
│           http://api-logger.al.interka.my.id                   │
│                                                                │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────┐    │
│  │ Config #1    │  │ Data Logs    │  │ User Management  │    │
│  │ Task Mgr     │  │ Execute      │  │ (admin only)     │    │
│  └──────┬───────┘  └──────┬───────┘  └──────────────────┘    │
│         │                 │                                    │
└─────────┼─────────────────┼────────────────────────────────────┘
          │                 │
          ▼                 ▼
┌──────────────────┐  ┌──────────────────┐
│  Aplikasi 1      │  │  Aplikasi 2      │
│  Task Manager    │  │  Issue Tracker   │
│  (PHP Native)    │  │  (PHP Native)    │
└──────────────────┘  └──────────────────┘

⚙️ Mekanisme Deduplikasi

  1. ApiLoggerService::executeAndLog() generate hash: md5(app_name | method | url | request_data)
  2. Cek Redis → cache hit (TTL 5 menit): return hasil cache, tidak insert ApiLog maupun DataLog
  3. Cache miss: eksekusi API via Guzzle → insert ApiLog → cache result → caller insert DataLog hanya jika status === success
  4. Gagal (4xx/5xx/error): ApiLog tetap tercatat, DataLog tidak dibuat

🌐 Domain & Port

Aplikasi Domain Internal Test
API Logger http://api-logger.al.interka.my.id http://127.0.0.1:8080
Task Manager http://aplikasi1.al.interka.my.id curl -H "Host: aplikasi1..." http://127.0.0.1:8080/api.php
Issue Tracker http://aplikasi2.al.interka.my.id curl -H "Host: aplikasi2..." http://127.0.0.1:8080/api.php

⚠️ Tes lokal via 127.0.0.1:8080 + Host header — openresty proxy publik membatasi path.

🔧 Quick Start

cd /root/project/LOGS/api-logger

# Reset + seed
php artisan migrate:fresh --seed

# Jalankan Caddy + PHP-FPM
nohup php-fpm8.5 -D > /dev/null 2>&1 &
nohup caddy run --config /etc/caddy/Caddyfile > /tmp/caddy.log 2>&1 &

# Eksekusi API via CLI
php artisan datalog:execute 1           # App1
php artisan datalog:execute 2 --notif   # App2 + notifikasi

# Clear Redis (untuk tes dedupe)
redis-cli -h redis_cache -p 6379 --user root -a admin123 --no-auth-warning FLUSHALL

🔐 Default Credentials

Role Email Password
Admin admin@example.com password
User user@example.com password

⚠️ Ubah password sebelum production!

🗄️ Database

Tabel Keterangan
users 2 user seed (admin + user)
api_configurations 2 endpoint (App1 + App2), bearer token auto-generate
api_logs Log sistem — selalu tercatat (success & failed)
data_logs Log manual — hanya tercatat jika success + bukan cache
aplikasi1_data 4 seed task (pending, proses, selesai, batal)
aplikasi2_data 4 seed issue (open, progress, review, closed)

📁 Project Structure

/root/project/LOGS/
├── api-logger/                    # Laravel 13 — Dashboard
│   ├── app/
│   │   ├── Http/Controllers/      # Auth, Dashboard, Config, DataLog, User, Profile
│   │   ├── Models/                # User, ApiConfiguration, ApiLog, DataLog
│   │   ├── Services/              # ApiLoggerService (Guzzle + Redis dedupe)
│   │   └── Console/Commands/      # DatalogExecute (CLI)
│   ├── database/
│   │   ├── migrations/            # 8 tabel
│   │   └── seeders/               # User, Config, ApiLog, App1/App2 data
│   ├── resources/views/           # Blade + Tailwind (datalogs/show: JSON rapi)
│   ├── routes/web.php             # Auth + dashboard + throttle middleware
│   └── public/                    # Document root Caddy
│
├── aplikasi1/                     # PHP Native — Task Manager
│   ├── config.php                 # PDO → mariadb_db
│   ├── api.php                    # JSON API (GET list + POST insert)
│   └── index.php                  # Web form Tailwind CDN
│
├── aplikasi2/                     # PHP Native — Issue Tracker
│   ├── config.php
│   ├── api.php
│   └── index.php
│
├── CATATAN.md                     # Dokumentasi lengkap + troubleshooting
├── README.md                      # ◀ File ini
├── PRD.md                         # Product Requirement Document
├── DEVELOPMENT_GUIDE.md           # Panduan development
└── SETUP_INSTRUCTIONS.md          # Instruksi setup

🔒 Security

  • CSRF Protection (Laravel built-in)
  • Rate Limiting — 60 req/min di semua route authenticated
  • SQL Injection Prevention (PDO prepared statements)
  • XSS Protection (Blade {{ }} auto-escape)
  • Password Hashing (Bcrypt)
  • API Token Encryption (AES-256)
  • Bearer Token — 64 char random, bisa regenerate via UI

📝 Common Commands

cd /root/project/LOGS/api-logger

# Database
php artisan migrate:fresh --seed     # Reset + seed (hati-hati: hapus semua data)
php artisan tinker                   # Shell interaktif

# Cache
php artisan cache:clear              # Hapus Redis cache
php artisan config:clear             # Hapus config cache
php artisan optimize                 # Cache config/route/event/view

# Data Logs
php artisan datalog:execute 1        # Eksekusi config #1
php artisan datalog:execute 2 --notif # Eksekusi config #2 + notifikasi

# Testing
php artisan test                     # Run semua test
php artisan route:list               # Lihat semua route

📦 Deployment

# Production .env
APP_ENV=production
APP_DEBUG=false
CACHE_DRIVER=redis
SESSION_DRIVER=redis

# Optimize
composer install --no-dev --optimize-autoloader
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Permissions
chmod -R 775 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache

🩺 Troubleshooting

Error Fix
touch(): Utime failed: Operation not permitted File cache dibuat oleh root tapi PHP-FPM jalan sebagai www-datachown -R www-data:www-data storage bootstrap/cache && chmod -R 775 storage bootstrap/cache
500 / blank page php artisan config:clear && php artisan cache:clear && php artisan optimize
Redis auth error .env: REDIS_USERNAME=root, REDIS_PASSWORD=admin123, REDIS_HOST=redis_cache
migrate:fresh hapus App1/App2 Seeder sudah recreate aplikasi1_data + aplikasi2_data otomatis
Caddy tidak jalan nohup caddy run --config /etc/caddy/Caddyfile > /tmp/caddy.log 2>&1 &
Domain publik 404 Tes via 127.0.0.1:8080 + Host header (openresty proxy batasi path)

📄 License

MIT License


Last Updated: 29 Juli 2026
Version: 1.1.0 — Redis dedupe fix, failed execution guard, dashboard cache, rate limiting, timezone Asia/Jakarta, pure JSON response data, permission fix