summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/libsignal/logger/DefaultLogger.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/DefaultLogger.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/DefaultLogger.go')
-rw-r--r--vendor/go.mau.fi/libsignal/logger/DefaultLogger.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/go.mau.fi/libsignal/logger/DefaultLogger.go b/vendor/go.mau.fi/libsignal/logger/DefaultLogger.go
new file mode 100644
index 00000000..62515bff
--- /dev/null
+++ b/vendor/go.mau.fi/libsignal/logger/DefaultLogger.go
@@ -0,0 +1,85 @@
+package logger
+
+import (
+ "fmt"
+ "strings"
+ "time"
+)
+
+// DefaultLogger is used if no logger has been set up.
+type defaultLogger struct {
+ namespaces []string
+}
+
+// log simply logs the given message to stdout if the message
+// caller is allowed to log.
+func (d *defaultLogger) log(level, caller, msg string) {
+ if !d.shouldLog(caller) {
+ // return
+ }
+ t := time.Now()
+ fmt.Println(
+ "["+level+"]",
+ t.Format(time.RFC3339),
+ caller,
+ "▶ ",
+ msg,
+ )
+}
+
+// shouldLog determines whether or not the given caller should
+// be allowed to log messages.
+func (d *defaultLogger) shouldLog(caller string) bool {
+ shouldLog := false
+ d.ensureNamespaces()
+ for _, namespace := range d.namespaces {
+ if namespace == "all" {
+ shouldLog = true
+ }
+ if strings.Contains(caller, namespace) {
+ shouldLog = true
+ }
+ }
+
+ return shouldLog
+}
+
+// ensureNamespaces checks to see if our list of loggable namespaces
+// has been initialized or not. If not, it defaults to log all.
+func (d *defaultLogger) ensureNamespaces() {
+ if d.namespaces == nil {
+ d.namespaces = []string{"all"}
+ }
+}
+
+// Debug is used to log debug messages.
+func (d *defaultLogger) Debug(caller, msg string) {
+ //d.log("DEBUG", caller, msg)
+}
+
+// Info is used to log info messages.
+func (d *defaultLogger) Info(caller, msg string) {
+ d.log("INFO", caller, msg)
+}
+
+// Warning is used to log warning messages.
+func (d *defaultLogger) Warning(caller, msg string) {
+ d.log("WARNING", caller, msg)
+}
+
+// Error is used to log error messages.
+func (d *defaultLogger) Error(caller, msg string) {
+ d.log("ERROR", caller, msg)
+}
+
+// Configure takes a configuration string separated by commas
+// that contains all the callers that should be logged. This
+// allows granular logging of different go files.
+//
+// Example:
+// logger.Configure("RootKey.go,Curve.go")
+// logger.Configure("all")
+//
+func (d *defaultLogger) Configure(settings string) {
+ d.namespaces = strings.Split(settings, ",")
+}