summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-27 14:00:32 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-27 14:00:32 +0200
commitd8e466712a4c5af17c27953b38f1b4e7d914d5cf (patch)
tree449149eaebdf8494a2bf8e3c7428b85814cd28b5 /internal
parenta943641fdae051346355a3aaf1d8887da674c97c (diff)
Log: Add 'inherit' that sets the error level as the log level
Diffstat (limited to 'internal')
-rw-r--r--internal/log/log.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/log/log.go b/internal/log/log.go
index c0e9c7d..7241164 100644
--- a/internal/log/log.go
+++ b/internal/log/log.go
@@ -18,10 +18,16 @@ type FileLogger struct {
type LogLevel int8
const (
+ // No level set, not allowed
LOG_NOTSET LogLevel = iota
+ // Log info, this message is not an error
LOG_INFO
+ // Log only to provide a warning, the app still functions
LOG_WARNING
+ // Log to provide a generic error, the app still functions but some functionality might not work
LOG_ERROR
+ // Log to provide a fatal error, the app cannot function correctly when such an error occurs
+ LOG_FATAL
)
func (e LogLevel) String() string {
@@ -34,6 +40,8 @@ func (e LogLevel) String() string {
return "WARNING"
case LOG_ERROR:
return "ERROR"
+ case LOG_FATAL:
+ return "FATAL"
default:
return "UNKNOWN"
}
@@ -60,6 +68,22 @@ func (logger *FileLogger) Init(level LogLevel, name string, directory string) er
return nil
}
+func (logger *FileLogger) Inherit(err error, msg string) {
+ level := types.GetErrorLevel(err)
+
+ switch(level) {
+ case types.ERR_INFO:
+ logger.Info(msg)
+ case types.ERR_WARNING:
+ logger.Warning(msg)
+ case types.ERR_OTHER:
+ logger.Error(msg)
+ case types.ERR_FATAL:
+ logger.Fatal(msg)
+ }
+
+}
+
func (logger *FileLogger) Info(msg string) {
logger.log(LOG_INFO, msg)
}
@@ -72,6 +96,10 @@ func (logger *FileLogger) Error(msg string) {
logger.log(LOG_ERROR, msg)
}
+func (logger *FileLogger) Fatal(msg string) {
+ logger.log(LOG_FATAL, msg)
+}
+
func (logger *FileLogger) Close() {
logger.File.Close()
}