feat: docs api design
This commit is contained in:
38
pkg/logger/setup.go
Normal file
38
pkg/logger/setup.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"octopus"
|
||||
"octopus/internal/config"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/rs/zerolog/pkgerrors"
|
||||
)
|
||||
|
||||
func Setup() {
|
||||
cfg := config.Get()
|
||||
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
|
||||
|
||||
writers := []io.Writer{}
|
||||
if config.Get().IsLocal {
|
||||
writers = append(writers, zerolog.NewConsoleWriter())
|
||||
} else {
|
||||
writers = append(writers, os.Stderr)
|
||||
}
|
||||
if dsn := cfg.Sentry.DSN; dsn != "" {
|
||||
sentryWriter, err := NewSentryWriter(
|
||||
cfg.Sentry.DSN,
|
||||
WithDebug(cfg.Debug),
|
||||
WithEnvironment(cfg.Sentry.Environment),
|
||||
WithRelease(octopus.Version),
|
||||
WithServerName("octopus-service"),
|
||||
)
|
||||
if err == nil {
|
||||
writers = append(writers, sentryWriter)
|
||||
}
|
||||
}
|
||||
log.Logger = zerolog.New(io.MultiWriter(writers...)).With().Stack().Timestamp().Logger()
|
||||
}
|
||||
Reference in New Issue
Block a user