This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Nikita edited this page Mar 15, 2019
·
4 revisions
ALog - Fast and asynchronous logger.
go get -u github.com/mylockerteam/aLog
package main
import (
"alog/Alog"
"io"
"sync"
"time"
)
var logger struct{
instance *Alog.Log
once sync.Once
}
func GetLogger() *Alog.Log {
logger.once.Do(func() {
logger.instance = Alog.Create(&Alog.Config{
TimeFormat: time.RFC3339Nano,
LogFileLine: false,
Loggers: Alog.LoggerMap{
Alog.LoggerInfo: getInfoLogger(),
Alog.LoggerWrn: getWarningLogger(),
Alog.LoggerErr: getErrorLogger(),
},
})
})
return logger.instance
}
func getInfoLogger() *Alog.Logger {
return &Alog.Logger{
Channel: make(chan string, 100),
Strategies: []io.Writer{
Alog.GetFileStrategy("<Full absolute file path>"),
Alog.GetDefaultStrategy(),
},
}
}
func getWarningLogger() *Alog.Logger {
return &Alog.Logger{
Channel: make(chan string, 100),
Strategies: []io.Writer{
Alog.GetFileStrategy("<Full absolute file path>"),
Alog.GetDefaultStrategy(),
},
}
}
func getErrorLogger() *Alog.Logger {
sendCloser := mailSender.GetCloser(gomail.NewDialer(mailSender.ParseEss("host:post;username;password")))
sender := mailSender.Create(&mailSender.Sender{
Channel: make(chan mailSender.Message, 100),
Closer: sendCloser,
})
msg := gomail.NewMessage()
msg.SetHeader("From", "Example <[email protected]>")
msg.SetHeader("Bcc", "<[email protected]>")
msg.SetHeader("Subject", "This is test")
// Placeholder {{ .Data }} is required!
tpl, _ := template.New("test").Parse("<pre><code>{{ .Data }}</code></pre>")
return &alog.Logger{
Channel: make(chan string, 100),
Strategies: []io.Writer{
alog.GetFileStrategy("<Full absolute file path>"),
alog.GetEmailStrategy(sender, msg, tpl),
alog.GetDefaultStrategy(),
},
}
}