summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/libsignal/logger/Logger.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-01-31 00:27:37 +0100
committerWim <wim@42.be>2022-03-20 14:57:48 +0100
commite3cafeaf9292f67459ff1d186f68283bfaedf2ae (patch)
treeb69c39620aa91dba695b3b935c6651c0fb37ce75 /vendor/go.mau.fi/libsignal/logger/Logger.go
parente7b193788a56ee7cdb02a87a9db0ad6724ef66d5 (diff)
downloadmatterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.tar.gz
matterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.tar.bz2
matterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.zip
Add dependencies/vendor (whatsapp)
Diffstat (limited to 'vendor/go.mau.fi/libsignal/logger/Logger.go')
-rw-r--r--vendor/go.mau.fi/libsignal/logger/Logger.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/go.mau.fi/libsignal/logger/Logger.go b/vendor/go.mau.fi/libsignal/logger/Logger.go
new file mode 100644
index 00000000..653320bf
--- /dev/null
+++ b/vendor/go.mau.fi/libsignal/logger/Logger.go
@@ -0,0 +1,89 @@
+// Package logger provides optional debug logging of the Signal library.
+package logger
+
+import (
+ "fmt"
+ "runtime"
+ "strconv"
+ "strings"
+)
+
+// Logger is a shared loggable interface that this library will use for all log messages.
+var Logger Loggable
+
+// Loggable is an interface for logging.
+type Loggable interface {
+ Debug(caller, message string)
+ Info(caller, message string)
+ Warning(caller, message string)
+ Error(caller, message string)
+ Configure(settings string)
+}
+
+// Setup will configure the shared logger to use the provided logger.
+func Setup(logger *Loggable) {
+ Logger = *logger
+}
+
+// ToString converts an arbitrary number of objects to a string for use in a logger.
+func toString(a ...interface{}) string {
+ return fmt.Sprint(a...)
+}
+
+// EnsureLogger will use the default logger if one was not set up.
+func ensureLogger() {
+ if Logger == nil {
+ // fmt.Println("Error: No logger was configured. Use `logger.Setup` to configure a logger.")
+ Logger = &defaultLogger{}
+ }
+}
+
+// GetCaller gets the go file name and line number that the logger was called from.
+func getCaller() string {
+ var file string
+ _, path, line, _ := runtime.Caller(2)
+ paths := strings.Split(path, "/")
+ if len(paths) > 0 {
+ file = paths[len(paths)-1]
+ } else {
+ file = "<unkn>"
+ }
+
+ return file + ":" + strconv.Itoa(line)
+}
+
+/*
+ * Go methods used by the library for logging.
+ */
+
+// Debug prints debug level logs.
+func Debug(msg ...interface{}) {
+ ensureLogger()
+ Logger.Debug(getCaller(), toString(msg...))
+}
+
+// Info prints info level logs.
+func Info(msg ...interface{}) {
+ ensureLogger()
+ Logger.Info(getCaller(), toString(msg...))
+}
+
+// Warning prints warning level logs.
+func Warning(msg ...interface{}) {
+ ensureLogger()
+ Logger.Warning(getCaller(), toString(msg...))
+}
+
+// Error prints error level logs.
+func Error(msg ...interface{}) {
+ ensureLogger()
+ Logger.Error(getCaller(), toString(msg...))
+}
+
+// Configure allows arbitrary logger configuration settings. The
+// default logger uses this method to configure what Go files
+// are allowed to log.
+func Configure(settings string) {
+ ensureLogger()
+ Logger.Configure(settings)
+}