mirror of
https://github.com/garraflavatra/rolens.git
synced 2024-11-21 22:18:59 +01:00
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package internal
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
type AppLogger struct {
|
|
directory string
|
|
filename string
|
|
filepath string
|
|
}
|
|
|
|
func NewAppLogger(directory, filename string) *AppLogger {
|
|
return &AppLogger{
|
|
directory: directory,
|
|
filename: filename,
|
|
filepath: path.Join(directory, filename),
|
|
}
|
|
}
|
|
|
|
func (l *AppLogger) Print(message string) {
|
|
os.MkdirAll(l.directory, 0755)
|
|
f, _ := os.OpenFile(l.filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
f.WriteString(message)
|
|
f.Close()
|
|
}
|
|
|
|
func (l *AppLogger) Println(message string) {
|
|
l.Print(message + "\n")
|
|
}
|
|
|
|
func (l *AppLogger) Trace(message string) {
|
|
l.Println("TRACE | " + message)
|
|
}
|
|
|
|
func (l *AppLogger) Debug(message string) {
|
|
if strings.HasPrefix(message, "[ExternalAssetHandler]") {
|
|
return
|
|
}
|
|
l.Println("DEBUG | " + message)
|
|
}
|
|
|
|
func (l *AppLogger) Info(message string) {
|
|
l.Println("INFO | " + message)
|
|
}
|
|
|
|
func (l *AppLogger) Warning(message string) {
|
|
l.Println("WARN | " + message)
|
|
}
|
|
|
|
func (l *AppLogger) Error(message string) {
|
|
l.Println("ERROR | " + message)
|
|
}
|
|
|
|
func (l *AppLogger) Fatal(message string) {
|
|
l.Println("FATAL | " + message)
|
|
os.Exit(1)
|
|
}
|