summaryrefslogtreecommitdiff
path: root/logger.go
diff options
context:
space:
mode:
Diffstat (limited to 'logger.go')
-rw-r--r--logger.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/logger.go b/logger.go
new file mode 100644
index 0000000..010749a
--- /dev/null
+++ b/logger.go
@@ -0,0 +1,41 @@
+package logging
+
+import (
+ "fmt"
+ "log"
+)
+
+type Logger struct {
+ Level LevelEnum
+
+ ns string
+}
+
+func NewLogger(level LevelEnum) *Logger {
+ return &Logger{
+ Level: level,
+ }
+}
+
+func (l *Logger) WithNS(ns string) *Logger {
+ return &Logger{
+ Level: l.Level,
+ ns: formatNS(ns),
+ }
+}
+
+func (l *Logger) Logf(level LevelEnum, format string, args ...any) {
+ if level > l.Level {
+ return
+ }
+ log.Printf("%s%s %s", l.ns, level.Format(), fmt.Sprintf(format, args...))
+}
+
+func (l *Logger) Errorf(format string, args ...any) { l.Logf(Error, format, args...) }
+func (l *Logger) Warnf(format string, args ...any) { l.Logf(Warn, format, args...) }
+func (l *Logger) Infof(format string, args ...any) { l.Logf(Info, format, args...) }
+func (l *Logger) Debugf(format string, args ...any) { l.Logf(Debug, format, args...) }
+
+func formatNS(ns string) string {
+ return colorize("["+ns+"]", Purple)
+}