Reorganise repo
This commit is contained in:
36
log/log.go
Normal file
36
log/log.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"git.fjla.uk/owlboard/timetable-mgr/helpers"
|
||||
)
|
||||
|
||||
var Msg *zap.Logger
|
||||
|
||||
// Initialises the logger
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
// Create a custom configuration with a human-readable "Console" encoder
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder // Adds color to log levels
|
||||
|
||||
// Determine the log level based on the runtime mode
|
||||
logLevel := zapcore.DebugLevel
|
||||
if helpers.Runtime == "production" {
|
||||
logLevel = zapcore.InfoLevel
|
||||
}
|
||||
|
||||
// Set the log level
|
||||
config.Level = zap.NewAtomicLevelAt(logLevel)
|
||||
|
||||
Msg, err = config.Build() // Potential source of the error
|
||||
if err != nil {
|
||||
panic("Failed to initialize logger: " + err.Error())
|
||||
}
|
||||
|
||||
// Log the selected log level (optional, can be helpful for debugging)
|
||||
Msg.Info("Log level set to: " + logLevel.String())
|
||||
}
|
||||
Reference in New Issue
Block a user