A => LICENSE +21 -0
@@ 1,21 @@
+MIT License
+
+Copyright (c) 2022 Thorben Günther
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
A => go.mod +3 -0
@@ 1,3 @@
+module git.xenrox.net/~xenrox/go-log
+
+go 1.19
A => log.go +70 -0
@@ 1,70 @@
+package log
+
+import (
+ "io"
+ "log"
+ "os"
+)
+
+type Level int
+
+const (
+ Error Level = iota
+ Warning
+ Info
+ Debug
+)
+
+type Logger struct {
+ *log.Logger
+ level Level
+}
+
+func NewDefaultLogger() *Logger {
+ return &Logger{Logger: log.New(os.Stderr, "", log.LstdFlags), level: Info}
+}
+
+func New(out io.Writer, level Level) *Logger {
+ return &Logger{Logger: log.New(out, "", log.LstdFlags), level: level}
+}
+
+func (l *Logger) SetLevel(level Level) {
+ l.level = level
+}
+
+func (l *Logger) Fatalf(format string, v ...interface{}) {
+ format = "FATAL: " + format
+ l.Logger.Fatalf(format, v...)
+}
+
+func (l *Logger) Errorf(format string, v ...interface{}) {
+ format = "ERROR: " + format
+ l.Logger.Printf(format, v...)
+}
+
+func (l *Logger) Warningf(format string, v ...interface{}) {
+ if l.level < Warning {
+ return
+ }
+
+ format = "WARNING: " + format
+ l.Logger.Printf(format, v...)
+}
+
+func (l *Logger) Infof(format string, v ...interface{}) {
+ if l.level < Info {
+ return
+ }
+
+ format = "INFO: " + format
+ l.Logger.Printf(format, v...)
+}
+
+func (l *Logger) Debugf(format string, v ...interface{}) {
+ if l.level < Debug {
+ return
+ }
+
+ format = "DEBUG: " + format
+ l.Logger.Printf(format, v...)
+}