-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee8fed4
commit ac60aed
Showing
6 changed files
with
135 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
package clarum | ||
|
||
import ( | ||
"fmt" | ||
"github.com/goclarum/clarum/core/config" | ||
"github.com/goclarum/clarum/core/control" | ||
"log/slog" | ||
"os" | ||
"github.com/goclarum/clarum/core/logging" | ||
) | ||
|
||
func Setup() { | ||
slog.Info(fmt.Sprintf("Starting clarum %s", config.Version())) | ||
|
||
// TODO: go 1.22 will allow us to set the level on the default logger without changing the format | ||
// this change is what we need: https://github.com/golang/go/commit/3188758653fc7d2b229e234273d41878ddfdd5f2 | ||
// release date February 2024 | ||
h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: config.LoggingLevel()}) | ||
slog.SetDefault(slog.New(h)) | ||
logging.Infof("Starting clarum %s", config.Version()) | ||
} | ||
|
||
func Finish() { | ||
slog.Info("Waiting for all actions to finish.") | ||
logging.Info("Waiting for all actions to finish.") | ||
|
||
control.RunningActions.Wait() | ||
|
||
slog.Info("All actions finished.") | ||
logging.Info("All actions finished.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package logging | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
var internalLogger = log.New(os.Stdout, "", log.LstdFlags|log.Lmicroseconds) | ||
var defaultLogger = NewLogger(slog.LevelInfo, "") | ||
|
||
type Logger struct { | ||
level slog.Level | ||
prefix string | ||
} | ||
|
||
func NewLogger(level slog.Level, prefix string) *Logger { | ||
return &Logger{level, prefix} | ||
} | ||
|
||
func (logger *Logger) Info(message string) { | ||
if logger.level <= slog.LevelInfo { | ||
internalLogger.Println("INFO " + logger.prefix + message) | ||
} | ||
} | ||
|
||
func (logger *Logger) Infof(format string, a ...any) { | ||
if logger.level <= slog.LevelInfo { | ||
internalLogger.Println("INFO " + logger.prefix + fmt.Sprintf(format, a...)) | ||
} | ||
} | ||
|
||
func (logger *Logger) Debug(message string) { | ||
if logger.level <= slog.LevelDebug { | ||
internalLogger.Println("DEBUG " + logger.prefix + message) | ||
} | ||
} | ||
|
||
func (logger *Logger) Debugf(format string, a ...any) { | ||
if logger.level <= slog.LevelDebug { | ||
internalLogger.Println("DEBUG " + logger.prefix + fmt.Sprintf(format, a...)) | ||
} | ||
} | ||
|
||
func (logger *Logger) Warn(message string) { | ||
if logger.level <= slog.LevelWarn { | ||
internalLogger.Println("WARN " + logger.prefix + message) | ||
} | ||
} | ||
|
||
func (logger *Logger) Warnf(format string, a ...any) { | ||
if logger.level <= slog.LevelWarn { | ||
internalLogger.Println("WARN " + logger.prefix + fmt.Sprintf(format, a...)) | ||
} | ||
} | ||
|
||
func (logger *Logger) Error(message string) { | ||
if logger.level <= slog.LevelError { | ||
internalLogger.Println("ERROR " + logger.prefix + message) | ||
} | ||
} | ||
|
||
func (logger *Logger) Errorf(format string, a ...any) { | ||
if logger.level <= slog.LevelError { | ||
internalLogger.Println("ERROR " + logger.prefix + fmt.Sprintf(format, a...)) | ||
} | ||
} | ||
|
||
func (logger *Logger) Prefix() string { | ||
return logger.prefix | ||
} | ||
|
||
// calls on the default logger | ||
|
||
func Info(message string) { | ||
defaultLogger.Info(message) | ||
} | ||
|
||
func Infof(format string, a ...any) { | ||
defaultLogger.Infof(format, a...) | ||
} | ||
|
||
func Debug(message string) { | ||
defaultLogger.Debug(message) | ||
} | ||
|
||
func Debugf(format string, a ...any) { | ||
defaultLogger.Debugf(format, a...) | ||
} | ||
|
||
func Warn(message string) { | ||
defaultLogger.Warn(message) | ||
} | ||
|
||
func Warnf(format string, a ...any) { | ||
defaultLogger.Warnf(format, a...) | ||
} | ||
|
||
func Error(message string) { | ||
defaultLogger.Error(message) | ||
} | ||
|
||
func Errorf(format string, a ...any) { | ||
defaultLogger.Errorf(format, a...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters