Skip to content

Commit

Permalink
Merge pull request #2 from Alonza0314/feat/file-logger
Browse files Browse the repository at this point in the history
chore: make file logger export
  • Loading branch information
Alonza0314 authored Feb 19, 2025
2 parents fb22d77 + 18d8889 commit adb6162
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions fileLogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"path/filepath"
)

type fileLogger struct {
type FileLogger struct {
file *os.File
logger *log.Logger
color bool
}

func NewFileLogger(loggerFilePath string, opts ...Option) *fileLogger {
func NewFileLogger(loggerFilePath string, opts ...Option) *FileLogger {
options := &options{
flag: DEFAULT_FLAG,
perm: DEFAULT_PERM,
Expand Down Expand Up @@ -42,49 +42,50 @@ func NewFileLogger(loggerFilePath string, opts ...Option) *fileLogger {
panic(err)
}
logger := log.New(file, "", log.Ldate|log.Ltime)
return &fileLogger{
return &FileLogger{
file: file,
logger: logger,
color: options.color,
}
}

func (l *fileLogger) Close() {
func (l *FileLogger) Close() {
l.file.Close()
}

func (l *fileLogger) Info(tag string, msg string) {
func (l *FileLogger) Info(tag string, msg string) {
if l.color {
l.logger.Printf("%s[INFO]%s [%s]%s %s\n", COLOR_BLUE, COLOR_BLUE, tag, COLOR_RESET, msg)
} else {
l.logger.Printf("[INFO] [%s] %s\n", tag, msg)
}
}

func (l *fileLogger) Error(tag string, msg string) {
func (l *FileLogger) Error(tag string, msg string) {
if l.color {
l.logger.Printf("%s[EROR]%s [%s]%s %s\n", COLOR_RED, COLOR_BLUE, tag, COLOR_RESET, msg)
} else {
l.logger.Printf("[EROR] [%s] %s\n", tag, msg)
}
}

func (l *fileLogger) Warn(tag string, msg string) {
func (l *FileLogger) Warn(tag string, msg string) {
if l.color {
l.logger.Printf("%s[WARN]%s [%s]%s %s\n", COLOR_YELLOW, COLOR_BLUE, tag, COLOR_RESET, msg)
} else {
l.logger.Printf("[WARN] [%s] %s\n", tag, msg)
}
}

func (l *fileLogger) Test(tag string, msg string) {
func (l *FileLogger) Test(tag string, msg string) {
if l.color {
l.logger.Printf("%s[TEST]%s [%s]%s %s\n", COLOR_GREEN, COLOR_BLUE, tag, COLOR_RESET, msg)
} else {
l.logger.Printf("[TEST] [%s] %s\n", tag, msg)
}
}

func (l *fileLogger) Debug(tag string, msg string) {
func (l *FileLogger) Debug(tag string, msg string) {
if l.color {
l.logger.Printf("%s[DBUG]%s [%s]%s %s\n", COLOR_PURPLE, COLOR_BLUE, tag, COLOR_RESET, msg)
} else {
Expand Down

0 comments on commit adb6162

Please sign in to comment.