Logs API
Comprehensive logging system with filtering, metadata support, and multiple log levels
Overview
The Logs API provides a comprehensive logging system for your applications. Create, retrieve, and filter log entries with support for multiple log levels, service categorization, and custom metadata.
✨ Key Features
- • Multiple log levels (debug, info, warn, error)
- • Service-based categorization
- • Custom metadata support
- • Advanced filtering capabilities
- • Structured logging
Log Levels
DEBUG
Detailed information for diagnosing problems
INFO
General information about system operation
WARN
Warning messages for potential issues
ERROR
Error events that might still allow the application to continue
Create Log Entry
/api/v1/logs
Create a new log entry with level, message, and optional metadata.
Request Body
{
"level": "info",
"message": "User logged in successfully",
"service": "auth-service",
"metadata": {
"userId": "user_123",
"ip": "192.168.1.1",
"userAgent": "Mozilla/5.0..."
}
}
Example Request
curl -X POST \
-H "x-api-key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"level": "info",
"message": "User logged in successfully",
"service": "auth-service",
"metadata": {
"userId": "user_123"
}
}' \
"https://simplystack.dev/api/v1/logs"
List Log Entries
/api/v1/logs
Retrieve log entries with advanced filtering options.
Query Parameters
Parameter | Type | Description |
---|---|---|
level | string | Filter by log level: debug, info, warn, error |
service | string | Filter by service name |
limit | number | Number of entries to return (default: 50, max: 1000) |
since | string | ISO timestamp to filter logs after this time |
Example Request
curl -H "x-api-key: your_api_key_here" \
"https://simplystack.dev/api/v1/logs?level=error&service=auth-service&limit=10"
Example Response
{
"data": [
{
"id": "log_456",
"level": "error",
"message": "Database connection failed",
"service": "auth-service",
"metadata": {
"error": "Connection timeout",
"database": "users"
},
"created_at": "2024-01-15T10:30:00Z"
}
],
"total": 1,
"limit": 10
}
Get Log Entry
/api/v1/logs/{id}
Retrieve a specific log entry by ID.
SDK Usage
import { SimplyStackSDK } from "@simplystack-org/sdk";
const sdk = new SimplyStackSDK("your-api-key");
// Create a log entry
const { data: log, error } = await sdk.createLogEntry({
level: "info",
message: "User action completed",
service: "user-service",
metadata: {
userId: "123",
action: "profile_update"
}
});
// Search logs
const { data: logs } = await sdk.searchLogs({
level: "error",
service: "auth-service",
limit: 50
});
// Get specific log
const { data: logEntry } = await sdk.getLogEntry("log_123");
Best Practices
✅ Use Structured Logging
Include relevant metadata in your logs to make them searchable and useful for debugging.
📝 Consistent Service Names
Use consistent service names across your application to enable effective filtering and monitoring.
⚡ Appropriate Log Levels
Use appropriate log levels: DEBUG for development, INFO for general events, WARN for potential issues, ERROR for actual problems.