some improvments

This commit is contained in:
Adrian Zürcher
2026-01-01 11:00:23 +01:00
parent 8f313c00f0
commit ef0778c8b3
20 changed files with 305 additions and 385 deletions

View File

@@ -19,22 +19,22 @@ type Logger interface {
// Dummy Logger does nothing.
type DummyLogger struct{}
func (this DummyLogger) Error(format string, args ...any) {
func (DummyLogger) Error(format string, args ...any) {
}
func (this DummyLogger) Warning(format string, args ...any) {
func (DummyLogger) Warning(format string, args ...any) {
}
func (this DummyLogger) Notice(format string, args ...any) {
func (DummyLogger) Notice(format string, args ...any) {
}
func (this DummyLogger) Info(format string, args ...any) {
func (DummyLogger) Info(format string, args ...any) {
}
func (this DummyLogger) Debug(format string, args ...any) {
func (DummyLogger) Debug(format string, args ...any) {
}
func (this DummyLogger) Trace(format string, args ...any) {
func (DummyLogger) Trace(format string, args ...any) {
}
// Simple Console Logger that the tests use.
@@ -53,62 +53,56 @@ type ConsoleLogger struct {
LogLevel LogLevel
}
func NewConsoleLogger(logLevel LogLevel) *ConsoleLogger {
logger := ConsoleLogger{}
logger.LogLevel = logLevel
return &logger
}
// func NewConsoleLogger(logLevel LogLevel) *ConsoleLogger {
// logger := ConsoleLogger{}
// logger.LogLevel = logLevel
// return &logger
// }
func (this ConsoleLogger) Error(format string, args ...any) {
if this.LogLevel >= LogLevelError {
prefix := "[ERROR] "
this.output(os.Stdout, prefix, format, args...)
func (cL ConsoleLogger) Error(format string, args ...any) {
if cL.LogLevel >= LogLevelError {
cL.output(os.Stdout, "[ERROR] ", format, args...)
}
}
func (this ConsoleLogger) Warning(format string, args ...any) {
if this.LogLevel >= LogLevelWarning {
prefix := "[WARNING] "
this.output(os.Stdout, prefix, format, args...)
func (cL ConsoleLogger) Warning(format string, args ...any) {
if cL.LogLevel >= LogLevelWarning {
cL.output(os.Stdout, "[WARNING] ", format, args...)
}
}
func (this ConsoleLogger) Notice(format string, args ...any) {
if this.LogLevel >= LogLevelNotice {
prefix := "[NOTICE] "
this.output(os.Stdout, prefix, format, args...)
func (cL ConsoleLogger) Notice(format string, args ...any) {
if cL.LogLevel >= LogLevelNotice {
cL.output(os.Stdout, "[NOTICE] ", format, args...)
}
}
func (this ConsoleLogger) Info(format string, args ...any) {
if this.LogLevel >= LogLevelInfo {
prefix := "[INFO] "
this.output(os.Stdout, prefix, format, args...)
func (cL ConsoleLogger) Info(format string, args ...any) {
if cL.LogLevel >= LogLevelInfo {
cL.output(os.Stdout, "[INFO] ", format, args...)
}
}
func (this ConsoleLogger) Debug(format string, args ...any) {
if this.LogLevel >= LogLevelDebug {
prefix := "[DEBUG] "
this.output(os.Stdout, prefix, format, args...)
func (cL ConsoleLogger) Debug(format string, args ...any) {
if cL.LogLevel >= LogLevelDebug {
cL.output(os.Stdout, "[DEBUG] ", format, args...)
}
}
func (this ConsoleLogger) Trace(format string, args ...any) {
if this.LogLevel >= LogLevelTrace {
prefix := "[TRACE] "
this.output(os.Stdout, prefix, format, args...)
func (cL ConsoleLogger) Trace(format string, args ...any) {
if cL.LogLevel >= LogLevelTrace {
cL.output(os.Stdout, "[TRACE] ", format, args...)
}
}
var Log Logger = DummyLogger{}
func SetLogger(logger Logger) {
Log = logger
}
// func SetLogger(logger Logger) {
// Log = logger
// }
// output writes `format`, `args` log message prefixed by the source file name, line and `prefix`
func (this ConsoleLogger) output(f *os.File, prefix string, format string, args ...any) {
func (ConsoleLogger) output(f *os.File, prefix string, format string, args ...any) {
_, file, line, ok := runtime.Caller(3)
if !ok {
file = "???"

View File

@@ -1,11 +0,0 @@
package common
import (
"time"
)
const timeFormat = "2 January 2006 at 15:04"
func UtcTimeFormat(t time.Time) string {
return t.Format(timeFormat) + " UTC"
}

View File

@@ -1,17 +0,0 @@
// Package common contains common properties used by the subpackages.
package common
import (
"time"
)
const releaseYear = 2018
const releaseMonth = 11
const releaseDay = 17
const releaseHour = 11
const releaseMin = 30
// Holds version information, when bumping this make sure to bump the released at stamp also.
const Version = "2.2.0"
var ReleasedAt = time.Date(releaseYear, releaseMonth, releaseDay, releaseHour, releaseMin, 0, 0, time.UTC)