A reusable structured logger package built on zerolog with hourly file rotation, optional stdout/file output, and retention cleanup. It is optimized for Grafana-style filtering using project, appId, and serverId fields.
import "github.com/Rafay106/jsonlogger"
func main() {
log, err := jsonlogger.New(jsonlogger.Config{
Level: "info",
Dir: "logs",
Project: "geonavi",
AppID: "gps-parser",
ServerID: "instance-1",
RetentionDays: 7,
EnableStdout: true,
EnableFile: true,
})
if err != nil {
panic(err)
}
defer log.Close()
jsonlogger.Log.Info().Msg("starting application")
}- Use the global
jsonlogger.Loginstance for structured logging across packages. - Configure
Project,AppID, andServerIDfor app/server-level log filtering. - Set
EnableStdoutorEnableFileto control output destinations. - Update the module path in
go.modto your repository path before publishing.