gologger is a very simple logging package to do structured logging in go.
log/slog packagepackage main
import (
"strconv"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
)
func main() {
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
// gologger.DefaultLogger.SetFormatter(&formatter.JSON{})
gologger.Print().Msgf("\tgologger: sample test\t\n")
gologger.Info().Str("user", "pdteam").Msg("running simulation program")
for i := 0; i < 10; i++ {
gologger.Info().Str("count", strconv.Itoa(i)).Msg("running simulation step...")
}
gologger.Debug().Str("state", "running").Msg("planner running")
gologger.Warning().Str("state", "errored").Str("status", "404").Msg("could not run")
gologger.Fatal().Msg("bye bye")
}
gologger is fully compatible with Go's standard log/slog package. You can use gologger as an slog handler to get the same beautiful CLI output while leveraging the standard Go logging ecosystem.
package main
import (
"log/slog"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
)
func main() {
// Setup gologger as slog handler (one-time setup)
gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose)
slog.SetDefault(slog.New(gologger.DefaultLogger))
// Now both APIs produce identical output:
gologger.Info().Str("user", "john").Msg("Hello from gologger")
slog.Info("Hello from slog", slog.String("user", "john"))
// Both output: [INF] Hello from gologger [user=john]
// [INF] Hello from slog [user=john]
}
See the complete slog Compatibility Guide for:
gologger is made with 🖤 by the projectdiscovery team.
370 followers · starred Apr 2024
1,674 followers · starred Apr 2020
gologger is a very simple logging package to do structured logging in go.
log/slog packagepackage main
import (
"strconv"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
)
func main() {
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
// gologger.DefaultLogger.SetFormatter(&formatter.JSON{})
gologger.Print().Msgf("\tgologger: sample test\t\n")
gologger.Info().Str("user", "pdteam").Msg("running simulation program")
for i := 0; i < 10; i++ {
gologger.Info().Str("count", strconv.Itoa(i)).Msg("running simulation step...")
}
gologger.Debug().Str("state", "running").Msg("planner running")
gologger.Warning().Str("state", "errored").Str("status", "404").Msg("could not run")
gologger.Fatal().Msg("bye bye")
}
gologger is fully compatible with Go's standard log/slog package. You can use gologger as an slog handler to get the same beautiful CLI output while leveraging the standard Go logging ecosystem.
package main
import (
"log/slog"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
)
func main() {
// Setup gologger as slog handler (one-time setup)
gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose)
slog.SetDefault(slog.New(gologger.DefaultLogger))
// Now both APIs produce identical output:
gologger.Info().Str("user", "john").Msg("Hello from gologger")
slog.Info("Hello from slog", slog.String("user", "john"))
// Both output: [INF] Hello from gologger [user=john]
// [INF] Hello from slog [user=john]
}
See the complete slog Compatibility Guide for:
gologger is made with 🖤 by the projectdiscovery team.
370 followers · starred Apr 2024
1,674 followers · starred Apr 2020