initialize paraclub-ai-mailer project with core components and configuration
This commit is contained in:
58
internal/logger/logger.go
Normal file
58
internal/logger/logger.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log = logrus.New()
|
||||
|
||||
func Init(level string, filePath string) error {
|
||||
// Set log level
|
||||
lvl, err := logrus.ParseLevel(level)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.SetLevel(lvl)
|
||||
|
||||
// Configure output
|
||||
if filePath != "" {
|
||||
file, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.SetOutput(io.MultiWriter(os.Stdout, file))
|
||||
}
|
||||
|
||||
log.SetFormatter(&logrus.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Info(args ...interface{}) {
|
||||
log.Info(args...)
|
||||
}
|
||||
|
||||
func Error(args ...interface{}) {
|
||||
log.Error(args...)
|
||||
}
|
||||
|
||||
func Debug(args ...interface{}) {
|
||||
log.Debug(args...)
|
||||
}
|
||||
|
||||
func Warn(args ...interface{}) {
|
||||
log.Warn(args...)
|
||||
}
|
||||
|
||||
func WithField(key string, value interface{}) *logrus.Entry {
|
||||
return log.WithField(key, value)
|
||||
}
|
||||
|
||||
func WithFields(fields logrus.Fields) *logrus.Entry {
|
||||
return log.WithFields(fields)
|
||||
}
|
||||
Reference in New Issue
Block a user