Skip to content
Draft
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
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/Neon-Genesis-Linux/pen-bot

go 1.26.2

require github.com/disgoorg/disgo v0.19.3
require (
github.com/disgoorg/disgo v0.19.3
go.uber.org/zap v1.28.0
)

require (
github.com/disgoorg/godave v0.1.0 // indirect
Expand All @@ -12,6 +15,7 @@ require (
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.18.4 // indirect
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/sys v0.41.0 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxE
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
Expand Down
28 changes: 28 additions & 0 deletions modules/logger/aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package logger

import (
"go.uber.org/zap"
)

// These are aliases for Zap's field types.
var (
Any = zap.Any
Array = zap.Array
Bool = zap.Bool
Complex64 = zap.Complex64
Complex128 = zap.Complex128
Dict = zap.Dict
Float64 = zap.Float64
Float32 = zap.Float32
Int = zap.Int
NamedError = zap.NamedError
Namespace = zap.Namespace
Reflect = zap.Reflect
Skip = zap.Skip
Stack = zap.Stack
String = zap.String
Stringer = zap.Stringer
Time = zap.Time
Uint = zap.Uint
Object = zap.Object
)
67 changes: 67 additions & 0 deletions modules/logger/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package logger

import (
"go.uber.org/zap"
"os"
"sync"
)

var (
instance *zap.Logger // singleton logger instance
once sync.Once // sync primitive for ensuring logger init runs once
)

// creates a single logger instance for the module.
func ensureLogger() {
once.Do(func() {
var err error
if os.Getenv("ENV") == "production" {
instance, err = zap.NewProduction()
} else {
instance, err = zap.NewDevelopment()
}
if err != nil {
panic(err)
}
})
}

/* These functions shadow Zap's loggers' calls,
while ensuring the singleton instance is initialized */

func Info(msg string, fields ...zap.Field) {
ensureLogger()
instance.Info(msg, fields...)
}

func Error(msg string, fields ...zap.Field) {
ensureLogger()
instance.Error(msg, fields...)
}

func Debug(msg string, fields ...zap.Field) {
ensureLogger()
instance.Debug(msg, fields...)
}

func Warn(msg string, fields ...zap.Field) {
ensureLogger()
instance.Warn(msg, fields...)
}

func Fatal(msg string, fields ...zap.Field) {
ensureLogger()
instance.Fatal(msg, fields...)
}

func With(fields ...zap.Field) *zap.Logger {
ensureLogger()
return instance.With(fields...)
}

func Sync() error {
if instance != nil {
return instance.Sync()
}
return nil
}