LogScale is a scalable logging library written in Go, designed to handle logs efficiently with customizable log handlers, batch processing, and flexible logging levels. This package helps you implement scalable and structured logging in your Go applications.
- Customizable Handlers: Support for custom log handlers that can be implemented according to your needs.
- Batch Processing: Process logs in batches to improve performance and reduce I/O operations.
- Scalable Architecture: Efficient logging even with high loads due to its buffer-based design.
- Multiple Logging Levels: Support for different log levels like
INFO,DEBUG,WARN,ERROR, etc. - Asynchronous Logging: Non-blocking log calls for improved application performance.
- Structured Logging: Support for key-value pairs for better log analysis.
go get github.com/vivekjha1213/logscaleTo start using LogScale, create a logger with a specified buffer size and log messages with different levels.
package main
import (
"github.com/vivekjha1213/logscale"
)
func main() {
// Create a new logger with a buffer size of 100 entries
logger := logscale.NewLogger(100)
// Log an info message
logger.Log("INFO", "Application started", "MyService")
// Log an error message
logger.Log("ERROR", "Failed to load configuration", "MyService")
// Stop the logger when done
logger.Stop()
}You can create custom log handlers by implementing the LogHandler interface. For example:
package main
import (
"fmt"
"github.com/vivekjha1213/logscale"
)
// CustomHandler processes logs by printing them in a custom format
type CustomHandler struct{}
func (h *CustomHandler) HandleLog(entry logscale.LogEntry) error {
fmt.Printf("Custom Log [%s]: %s - %s\n", entry.Level, entry.Service, entry.Message)
return nil
}
func main() {
logger := logscale.NewLogger(100)
// Create and set a custom handler
customHandler := &CustomHandler{}
logscale.SetLogHandler(customHandler)
logger.Log("INFO", "Custom logging handler set", "MyService")
logger.Stop()
}LogScale allows logs to be processed in batches to increase efficiency under heavy loads. You can define batch sizes and intervals based on your system's needs.
package main
import (
"github.com/vivekjha1213/logscale"
"time"
)
func main() {
logger := logscale.NewLogger(1000)
// Configure batch processing
logger.ConfigureBatchProcessing(100, 5 * time.Second)
// Log messages will be processed in batches of 100 or every 5 seconds, whichever comes first
for i := 0; i < 1000; i++ {
logger.Log("INFO", fmt.Sprintf("Log entry %d", i), "BatchService")
}
logger.Stop()
}LogScale supports structured logging with key-value pairs for better log analysis:
logger.LogStructured("INFO", "User logged in", "AuthService", map[string]interface{}{
"user_id": 12345,
"ip_address": "192.168.1.1",
"login_time": time.Now(),
})To test your logging functionality, use Go's standard testing tools. For example:
go test ./logscalepackage logscale_test
import (
"testing"
"github.com/vivekjha1213/logscale"
)
func TestLogging(t *testing.T) {
logger := logscale.NewLogger(10)
logger.Log("INFO", "Test log", "TestService")
logger.Stop()
}We've included benchmarks to measure the performance of LogScale. Run them using:
go test -bench=. ./logscaleContributions are welcome! Please fork this repository and submit a pull request if you'd like to add features or improve the code.
- Fork it (https://github.com/vivekjha1213/logscale/fork)
- Create your feature branch (
git checkout -b feature/my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/my-new-feature) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by scalable logging solutions for large-scale applications.
- Thanks to the open-source Go community for guidance and support.
- Logo created with LogoMakr
- Badges provided by Shields.io
LogScale is proud to be an open-source project. We believe in the power of community-driven development and welcome contributions from developers around the world.
Made with ❤️ by Vivek Jha