This guide will walk you through sending your first logs to LogFlux using our Go SDK. You’ll have logs flowing into your dashboard in under 5 minutes!
Prerequisites
- A LogFlux account (sign up here)
- Go 1.19 or later installed
- An API key from your dashboard settings
Step 1: Install the Go SDK
|
|
Step 2: Create Your First Logger
Create a new file main.go
:
|
|
Step 3: Run Your Example
Replace your-api-key-here
with your actual API key and run:
|
|
You should see:
Log sent successfully!
Step 4: View Your Logs
- Open your LogFlux dashboard
- Navigate to the Logs section
- You should see your log entry with the message “Hello from LogFlux!”
Step 5: Send Structured Logs
Let’s send some more interesting structured logs:
|
|
Understanding Log Structure
LogFlux logs have the following structure:
- Level: Log severity (
debug
,info
,warning
,error
,critical
) - Message: Human-readable log message
- Timestamp: When the event occurred
- Labels: Key-value pairs for filtering and grouping (indexed)
- Fields: Additional structured data (searchable)
Best Practices
1. Use Consistent Labels
Labels are indexed and used for filtering. Use consistent naming:
|
|
2. Structure Your Fields
Use structured data in fields for better searchability:
|
|
3. Choose Appropriate Log Levels
- debug: Detailed diagnostic information
- info: General operational messages
- warning: Something unexpected but not critical
- error: Error conditions that need attention
- critical: System is unusable
Next Steps
- Learn about the API for direct HTTP integration
- Explore other SDKs for different languages
- Set up alerting based on your logs
- Try the CLI tools for log inspection