// Copyright (c) 2022 Bryan Joshua Pedini // License: GPL-3 ยท See LICENSE for more details package gobasiclogger import ( "log" "os" ) type Logger struct { logLevel int } func (l *Logger) Initialize(level *string) { if level == nil { *level = os.Getenv("LOGLEVEL") } if _stringInArray(*level, []string{"debug", "DEBUG", "dbg", "DBG"}) { l.logLevel = 7 } else if _stringInArray(*level, []string{"notice", "NOTICE", "not", "NOT"}) { l.logLevel = 6 } else if _stringInArray(*level, []string{"info", "INFO", "inf", "INF"}) { l.logLevel = 5 } else if _stringInArray(*level, []string{"warning", "WARNING", "warn", "WARN", "wrn", "WRN"}) { l.logLevel = 4 } else if _stringInArray(*level, []string{"error", "ERROR", "err", "ERR"}) { l.logLevel = 3 } else if _stringInArray(*level, []string{"critical", "CRITICAL", "crt", "CRT"}) { l.logLevel = 2 } else if _stringInArray(*level, []string{"fatal", "FATAL", "fat", "FAT"}) { l.logLevel = 1 } } func (l *Logger) Debug(i ...interface{}) { i = append([]interface{}{"[DBG]"}, i...) if l.logLevel > 6 { log.Println(i...) } } func (l *Logger) Notice(i ...interface{}) { i = append([]interface{}{"[NOT]"}, i...) if l.logLevel > 5 { log.Println(i...) } } func (l *Logger) Info(i ...interface{}) { i = append([]interface{}{"[INF]"}, i...) if l.logLevel > 4 { log.Println(i...) } } func (l *Logger) Warning(i ...interface{}) { i = append([]interface{}{"[WRN]"}, i...) if l.logLevel > 3 { log.Println(i...) } } func (l *Logger) Error(i ...interface{}) { i = append([]interface{}{"[ERR]"}, i...) if l.logLevel > 2 { log.Println(i...) } } func (l *Logger) Fatal(i ...interface{}) { i = append([]interface{}{"[FAT]"}, i...) if l.logLevel > 1 { log.Println(i...) } } func (l *Logger) Critical(i ...interface{}) { i = append([]interface{}{"[CRT]"}, i...) if l.logLevel > 0 { log.Println(i...) } }