Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/fogfish/logger/examples

go 1.23.1

replace github.com/fogfish/logger/v3 => ../

replace github.com/fogfish/logger/x/xlog => ../x/xlog

require (
github.com/fogfish/logger/v3 v3.2.0
github.com/fogfish/logger/x/xlog v0.0.0-00010101000000-000000000000
)
Empty file added examples/go.sum
Empty file.
38 changes: 38 additions & 0 deletions examples/observability/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log/slog"
"time"

log "github.com/fogfish/logger/v3"
"github.com/fogfish/logger/x/xlog"
)

func do() {
defer slog.Info("done something", slog.Any("duration", xlog.SinceNow()))

time.Sleep(100 * time.Millisecond)
}

func rate() {
ops := xlog.PerSecondNow()
defer slog.Info("done something", slog.Any("op/sec", ops))

time.Sleep(100 * time.Millisecond)
ops.Acc += 100
}

func demand() {
ops := xlog.MillisecondOpNow()
defer slog.Info("done something", slog.Any("ms/op", ops))

time.Sleep(100 * time.Millisecond)
ops.Acc += 10
}

func main() {
slog.SetDefault(log.New())
do()
rate()
demand()
}
32 changes: 32 additions & 0 deletions examples/slog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright (C) 2021 - 2025 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
// https://github.com/fogfish/logger
//

package main

import (
"context"
"log/slog"

log "github.com/fogfish/logger/v3"
)

func main() {
slog.SetDefault(log.New(log.WithLogLevel(log.DEBUG)))

obj := slog.Group("obj",
slog.Any("key", "val"),
)

slog.Debug("debug status about system.", obj)
slog.Info("informative status about system.", obj)
slog.Log(context.Background(), log.NOTICE, "system is failed, error is recovered, no impact.", obj)
slog.Warn("system is failed, unable to recover, degraded functionality.", obj)
slog.Error("system is failed, unable to recover from error.", obj)
slog.Log(context.Background(), log.CRITICAL, "system is failed, response actions must be taken immediately. Doing graceful exit.", obj)
slog.Log(context.Background(), log.EMERGENCY, "system is unusable, panic execution of app.", obj)
}
33 changes: 33 additions & 0 deletions examples/xlog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright (C) 2021 - 2025 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
// https://github.com/fogfish/logger
//

package main

import (
"io"
"log/slog"

log "github.com/fogfish/logger/v3"
"github.com/fogfish/logger/x/xlog"
)

func main() {
slog.SetDefault(log.New(log.WithLogLevel(log.DEBUG)))

obj := slog.Group("obj",
slog.Any("key", "val"),
)

slog.Debug("debug status about system.", obj)
slog.Info("informative status about system.", obj)
xlog.Notice("system is failed, error is recovered, no impact.", obj)
xlog.Warn("system is failed, unable to recover, degraded functionality.", io.EOF, obj)
xlog.Error("system is failed, unable to recover from error.", io.EOF, obj)
xlog.Critical("system is failed, response actions must be taken immediately. Doing graceful exit.", io.EOF, obj)
xlog.Emergency("system is unusable, panic execution of app.", io.EOF, obj)
}
Loading