1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2024-11-21 22:18:59 +01:00
rolens/internal/logger.go

61 lines
1.1 KiB
Go
Raw Permalink Normal View History

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)
2023-12-22 15:26:29 +01:00
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)
}