log-frmt
v1.0.3
Published
Format API log files
Readme
log-formatter
A powerful CLI tool to format and extract key information from API log files. Perfect for developers and DevOps engineers working with API logs.
Features
- 🚀 Formats API log files with lightning speed
- 🔍 Extracts key information: request, response, URLs, and timestamps
- 📁 Processes single files or entire directories
- 🛠️ Handles JSON, XML, and mixed content formats
- 📊 Progress tracking with visual indicators
- 🛡️ Robust error handling with detailed error codes
Installation
npm install -g log-formatterUsage
Basic Commands
Format a single file:
frmt log.txtFormat a file with absolute path:
frmt -a /path/to/your/log.txtFormat all files in current directory:
frmt -l .Format all files in specific directory:
frmt -l /path/to/logs/
Command Options
| Option | Description |
| ---------------- | ---------------------------------------- |
| [file] | Process a single file or directory |
| -a, --absolute | Absolute path to a file or directory |
| -l, --all | Process all files in specified directory |
| --version | Show package version |
| --help | Show help message |
How It Works
The formatter:
Parses API log files
Extracts these key fields:
leadIdrequestUrlrequestrequestTimeresponseresponseTime
Formats JSON content for better readability
Preserves XML content as-is
Creates new files with
_Fsuffix (e.g.,log.txt→log_F.txt)
Error Codes
| Code | Description | Solution | | ----- | --------------------------------- | ------------------------- | | FL001 | No valid files found | Check directory/file path | | FL002 | File not found | Verify file exists | | FL003 | File processing error | Check file permissions | | FL101 | Invalid log format (missing JSON) | Verify log file content | | FL102 | Main JSON parsing error | Check JSON validity | | FL201 | Request/response parsing error | Inspect problematic field |
Examples
Before Formatting
// collection: third_party_api_log
{
"_id": "5f9d9b3d7b8f9b0017b0b1a0",
"policyTypeId": "1",
"leadId": "68711864195688024da2d807",
"apiName": "motor-quotes",
"requestUrl": "https://example.com/api",
"request": "{\"key\":\"value\"}",
"requestTime": "2025-07-11T19:28:07.183+05:30",
"response": "<xml>...</xml>",
"responseTime": "2025-07-11T19:28:26.977+05:30",
"__v": 0
}After Formatting
{
"leadId": "68711864195688024da2d807",
"requestUrl": "https://example.com/api",
"request": {
"key": "value"
},
"requestTime": "2025-07-11T19:28:07.183+05:30",
"response": "<xml>...</xml>",
"responseTime": "2025-07-11T19:28:26.977+05:30"
}Contributing
Contributions are welcome! Please follow these steps:
Fork the repository
Create a new branch
git checkout -b feature/your-featureCommit your changes
git commit -am "Add some feature"Push to the branch
git push origin feature/your-featureCreate a Pull Request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Created with ❤️ by Ankur Report Issues | View on GitHub
