Log Management
Lovrabet CLI automatically records every command you execute, like an "operation history." These logs are very useful when encountering problems.
Why Do You Need Logs?
Imagine these scenarios:
- The API worked fine yesterday but fails today
- Build time is getting longer, but you don't know where it's slow
- Need to share error information with colleagues
Logs can help you solve these problems!
How to Use
View Logs
lovrabet logs
This displays recent operation records, including:
- What commands you executed
- When they were executed
- What the execution result was
- How long they took
Clear Logs
lovrabet logs --clear
When the log file is too large or you want to start recording fresh, you can clear all logs.
What Information Do Logs Contain?
Each log record contains the following information:
| Field | Description | Example |
|---|---|---|
timestamp | Execution time | 2024-09-18 14:30:25 |
level | Log level | info, success, error, warn |
command | Executed command | start, build, api-pull |
message | Operation description | Development server started successfully |
duration | Time taken (milliseconds) | 1500 |
details | Detailed information | Error stack, configuration info, etc. |
Log Level Descriptions
- 🟢 info: General information, such as "Pulling API"
- ✅ success: Successful operation, such as "Page created successfully"
- ⚠️ warn: Warning information, such as "Configuration missing, using default value"
- ❌ error: Error information, such as "Login failed"
Practical Scenarios
1️⃣ Troubleshooting
When a command fails, logs can help you quickly locate the problem:
# View logs after build failure
lovrabet logs
# You'll see information like:
# [ERROR] build failed: Module not found: 'missing-package'
# [INFO] Build duration: 3500ms
2️⃣ Performance Analysis
By comparing execution times across different periods, you can discover performance issues:
# View recent build times
lovrabet logs | grep "build"
# Example output:
# 2024-09-15: build success (2500ms)
# 2024-09-16: build success (3200ms)
# 2024-09-17: build success (4800ms) # Significantly slower!
3️⃣ Team Collaboration
When encountering problems, you can share relevant log information with colleagues:
# Export last 10 log entries
lovrabet logs | tail -10
# Or directly share the .lovrabet.log file
Log File Location
The log file is saved in .lovrabet.log in the project root directory.
# View log file location
ls -la .lovrabet.log
# View file content directly (not recommended, hard to read)
cat .lovrabet.log
Note: The log file is in JSON Lines format, which may not be very readable when viewed directly. It's recommended to use the
lovrabet logscommand to view logs.
Best Practices
1. Regular Cleanup
Log files grow over time, so it's recommended to clean them regularly:
# Clean old logs weekly
lovrabet logs --clear
2. Check Logs First When Errors Occur
Whenever a command fails, check the logs first:
# View logs immediately after command failure
lovrabet logs
3. Preserve Key Information
When encountering hard-to-reproduce issues, you can backup the logs:
# Backup current logs
cp .lovrabet.log .lovrabet.log.backup
Common Issues
What to Do If Log File Is Too Large?
Just clear it:
lovrabet logs --clear
What to Do If Logs Don't Display?
Check if you're in the project root directory:
# Confirm you're in project root
ls .lovrabetrc
# If this file doesn't exist, you're not in a Lovrabet project
cd /path/to/your/project
What to Do If You Want to View Logs for Another Project?
You need to switch to the corresponding project directory:
cd /path/to/other/project
lovrabet logs