Kết quả

0 log entries
Timestamp Level Event Category Action Result Content
Chọn bộ lọc và nhấn "Áp dụng bộ lọc" để xem logs

API để gửi logs

Endpoint: POST api/logs

Content-Type: application/json

📋 Cấu trúc Request:
{
  "timestamp": "2025-12-19T13:45:32.123Z",
  "level": "info",
  "app": "naviplus",
  "env": "production",
  "event": {
    "name": "email",
    "category": "authentication",
    "action": "send welcome email",
    "result": "success",
    "content": "template: welcome, subject: Welcome..."
  }
}
💡 Lưu ý quan trọng:
  • Content có thể rất dài: Không giới hạn độ dài, có thể gửi hàng nghìn ký tự
  • Ký tự đặc biệt: Hỗ trợ đầy đủ ký tự Unicode, emoji, newlines, tabs, quotes, backslashes...
  • Encoding: Luôn sử dụng UTF-8 và JSON.stringify() để đảm bảo encoding đúng
  • JSON escaping: Tự động xử lý bởi JSON.stringify(), không cần escape thủ công
🔷 JavaScript (Fetch API):
async function sendLog(logData) {
    try {
        // logData có thể chứa content rất dài và ký tự đặc biệt
        // JSON.stringify() tự động xử lý encoding và escaping
        const response = await fetch('api/logs', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            body: JSON.stringify(logData)  // ✅ Tự động encode UTF-8 và escape ký tự đặc biệt
        });
        
        const result = await response.json();
        return result;
    } catch (error) {
        console.error('Error sending log:', error);
        throw error;
    }
}

// Ví dụ với content dài và ký tự đặc biệt
const logData = {
    timestamp: new Date().toISOString(),
    level: "info",
    app: "naviplus",
    env: "production",
    event: {
        name: "email",
        category: "authentication",
        action: "send welcome email",
        result: "success",
        content: `Đây là nội dung rất dài với nhiều dòng...
        
Có thể chứa:
- Ký tự đặc biệt: !@#$%^&*()_+-=[]{}|;':\",./<>?
- Unicode: 中文, العربية, русский, Tiếng Việt
- Emoji: 😀 🎉 ✅ ❌ ⚠️ 🔥 💯
- Newlines và tabs: 
    Dòng 1
    Dòng 2
    Dòng 3
- JSON trong string: {"key": "value", "nested": {"data": 123}}
- SQL queries: SELECT * FROM users WHERE id = 123 AND status = 'active'
- Stack traces: Error: Something went wrong
    at function (file.js:123)
    at handler (file.js:456)
- HTML: 
Content
- Code: function test() { return "hello"; } - Quotes: "double quotes" và 'single quotes' - Backslashes: C:\\Users\\Documents\\file.txt Và nhiều hơn nữa... ${'A'.repeat(10000)}` // Có thể rất dài } }; await sendLog(logData);
🔷 PHP (cURL hoặc file_get_contents):
function sendLog($logData) {
    $url = 'https://your-biglogs.pages.dev/api/logs';
    
    // json_encode() tự động xử lý UTF-8 và escape ký tự đặc biệt
    $jsonData = json_encode($logData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($jsonData)
        ],
        CURLOPT_POSTFIELDS => $jsonData  // ✅ Tự động encode UTF-8
    ]);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    return json_decode($response, true);
}

// Ví dụ với content dài và ký tự đặc biệt
$logData = [
    'timestamp' => date('c'),
    'level' => 'info',
    'app' => 'naviplus',
    'env' => 'production',
    'event' => [
        'name' => 'email',
        'category' => 'authentication',
        'action' => 'send welcome email',
        'result' => 'success',
        'content' => "Đây là nội dung rất dài với nhiều dòng...\n\n" .
                    "Có thể chứa:\n" .
                    "- Ký tự đặc biệt: !@#\$%^&*()_+-=[]{}|;':\",./<>?\n" .
                    "- Unicode: 中文, العربية, русский, Tiếng Việt\n" .
                    "- Emoji: 😀 🎉 ✅ ❌ ⚠️ 🔥 💯\n" .
                    "- JSON: {\"key\": \"value\"}\n" .
                    "- SQL: SELECT * FROM users WHERE id = 123\n" .
                    "- HTML: 
Content
\n" . "- Quotes: \"double\" và 'single'\n" . "- Backslashes: C:\\\\Users\\\\Documents\\\\file.txt\n" . str_repeat("Và nhiều hơn nữa... ", 1000) // Có thể rất dài ] ]; $result = sendLog($logData);
💡 Tip:
  • JavaScript: Luôn dùng JSON.stringify() - tự động xử lý UTF-8 và escape
  • PHP: Luôn dùng json_encode() với flag JSON_UNESCAPED_UNICODE
  • Không cần: Escape thủ công, encode base64, hoặc xử lý ký tự đặc biệt trước khi gửi
  • Content-Type: Luôn đặt application/json; charset=utf-8 trong headers