/* ScheduleTogether Backend Copyright (C) 2024, Zervó Zadachin DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License version 3 for more details. This program incorporates external libraries for certain functionalities. These libraries are covered by their respective licenses, and their usage agreements are as outlined in their respective documentation or source code. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package logging import ( "fmt" "os" "time" ) type Logger struct { moduleName string } // NewLogger creates a new Logger instance func NewLogger(moduleName string) *Logger { return &Logger{moduleName: moduleName} } // Log logs a raw message with specified color coding func (l *Logger) logRaw(prefix string, msg string, color string) { now := time.Now().Format("2006-01-02 15:04:05") // Format for date and time (seconds) fmt.Printf("%s[\033[1m%s\033[0m] %s <%s> %s"+Reset+Newline, color, prefix, now, l.moduleName, msg) } // wraps logRaw for general information logs func (l *Logger) Info(msg string) { l.logRaw("INFO", msg, White) } // wraps logRaw for warning logs func (l *Logger) Warn(msg string) { l.logRaw("WARN", msg, Yellow) } // wraps logRaw for error logs func (l *Logger) Err(msg string) { l.logRaw("ERRO", msg, Red) } // wraps logRaw for error logs func (l *Logger) Fatal(msg string) { l.logRaw("FATAL", msg, Red) os.Exit(1) } // ANSI color codes const ( Reset string = "\033[0m" Bold string = "\033[1m" Underline string = "\033[4m" Newline string = "\n" Black string = "\033[30m" Red string = "\033[31m" Green string = "\033[32m" Yellow string = "\033[33m" Blue string = "\033[34m" Magenta string = "\033[35m" Cyan string = "\033[36m" White string = "\033[37m" )