From d346733b9b772a53a95175fa63c8a49b5161e647 Mon Sep 17 00:00:00 2001 From: Snoosaphone Date: Sat, 28 Dec 2019 19:51:10 -0600 Subject: [PATCH] Changing up the flow of the logging system, starting to move the tests into their own directory for organization. --- backend.go | 2 +- examples/example.go | 20 +++++++++++--------- examples/{example.png => screenshot.png} | Bin format.go | 6 +++--- level.go | 2 +- log_nix.go | 8 +------- logger.go | 2 +- memory.go | 8 +------- multi.go | 6 +----- syslog.go | 8 +------- syslog_fallback.go | 8 +------- example_test.go => tests/example_test.go | 2 +- format_test.go => tests/format_test.go | 14 +++++++------- level_test.go => tests/level_test.go | 2 +- log_test.go => tests/log_test.go | 6 +----- logger_test.go => tests/logger_test.go | 2 +- memory_test.go => tests/memory_test.go | 2 +- multi_test.go => tests/multi_test.go | 2 +- 18 files changed, 35 insertions(+), 65 deletions(-) rename examples/{example.png => screenshot.png} (100%) rename example_test.go => tests/example_test.go (98%) rename format_test.go => tests/format_test.go (93%) rename level_test.go => tests/level_test.go (99%) rename log_test.go => tests/log_test.go (96%) rename logger_test.go => tests/logger_test.go (99%) rename memory_test.go => tests/memory_test.go (99%) rename multi_test.go => tests/multi_test.go (98%) diff --git a/backend.go b/backend.go index 74d9201..c94afe3 100644 --- a/backend.go +++ b/backend.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger // defaultBackend is the backend used for all logging calls. var defaultBackend LeveledBackend diff --git a/examples/example.go b/examples/example.go index 2246367..4e87fbe 100644 --- a/examples/example.go +++ b/examples/example.go @@ -2,14 +2,16 @@ package main import ( "os" + + "mimirtech.net/gitea/GoUtilities/logger" ) -var log = logging.MustGetLogger("example") +var log = logger.MustGetLogger("example") // Example format string. Everything except the message has a custom color // which is dependent on the log level. Many fields have a custom output // formatting too, eg. the time returns the hour down to the milli second. -var format = logging.MustStringFormatter( +var format = logger.MustStringFormatter( `%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`, ) @@ -18,25 +20,25 @@ var format = logging.MustStringFormatter( type Password string func (p Password) Redacted() interface{} { - return logging.Redact(string(p)) + return logger.Redact(string(p)) } func main() { // For demo purposes, create two backend for os.Stderr. - backend1 := logging.NewLogBackend(os.Stderr, "", 0) - backend2 := logging.NewLogBackend(os.Stderr, "", 0) + backend1 := logger.NewLogBackend(os.Stderr, "", 0) + backend2 := logger.NewLogBackend(os.Stderr, "", 0) // For messages written to backend2 we want to add some additional // information to the output, including the used log level and the name of // the function. - backend2Formatter := logging.NewBackendFormatter(backend2, format) + backend2Formatter := logger.NewBackendFormatter(backend2, format) // Only errors and more severe messages should be sent to backend1 - backend1Leveled := logging.AddModuleLevel(backend1) - backend1Leveled.SetLevel(logging.ERROR, "") + backend1Leveled := logger.AddModuleLevel(backend1) + backend1Leveled.SetLevel(logger.ERROR, "") // Set the backends to be used. - logging.SetBackend(backend1Leveled, backend2Formatter) + logger.SetBackend(backend1Leveled, backend2Formatter) log.Debugf("debug %s", Password("secret")) log.Info("info") diff --git a/examples/example.png b/examples/screenshot.png similarity index 100% rename from examples/example.png rename to examples/screenshot.png diff --git a/format.go b/format.go index 7160674..10a46a1 100644 --- a/format.go +++ b/format.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import ( "bytes" @@ -191,8 +191,8 @@ type stringFormatter struct { // future. // // Experimental: -// %{longpkg} Full package path, eg. github.com/go-logging -// %{shortpkg} Base package path, eg. go-logging +// %{longpkg} Full package path, eg. mimirtech.net/gitea/GoUtilities/logger +// %{shortpkg} Base package path, eg. logger // %{longfunc} Full function name, eg. littleEndian.PutUint32 // %{shortfunc} Base function name, eg. PutUint32 // %{callpath} Call function path, eg. main.a.b.c diff --git a/level.go b/level.go index 98dd191..c5838c0 100644 --- a/level.go +++ b/level.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import ( "errors" diff --git a/log_nix.go b/log_nix.go index 4ff2ab1..11fd345 100644 --- a/log_nix.go +++ b/log_nix.go @@ -1,10 +1,4 @@ -// +build !windows - -// Copyright 2013, Örjan Persson. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package logging +package logger import ( "bytes" diff --git a/logger.go b/logger.go index 535ed9b..fac116e 100644 --- a/logger.go +++ b/logger.go @@ -5,7 +5,7 @@ // Package logging implements a logging infrastructure for Go. It supports // different logging backends like syslog, file and memory. Multiple backends // can be utilized with different log levels per backend and logger. -package logging +package logger import ( "bytes" diff --git a/memory.go b/memory.go index 8d5152c..1e55039 100644 --- a/memory.go +++ b/memory.go @@ -1,10 +1,4 @@ -// Copyright 2013, Örjan Persson. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !appengine - -package logging +package logger import ( "sync" diff --git a/multi.go b/multi.go index 3731653..77704b7 100644 --- a/multi.go +++ b/multi.go @@ -1,8 +1,4 @@ -// Copyright 2013, Örjan Persson. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package logging +package logger // TODO remove Level stuff from the multi logger. Do one thing. diff --git a/syslog.go b/syslog.go index 4faa531..ea6c1f0 100644 --- a/syslog.go +++ b/syslog.go @@ -1,10 +1,4 @@ -// Copyright 2013, Örjan Persson. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//+build !windows,!plan9 - -package logging +package logger import "log/syslog" diff --git a/syslog_fallback.go b/syslog_fallback.go index 91bc18d..3aa90c2 100644 --- a/syslog_fallback.go +++ b/syslog_fallback.go @@ -1,10 +1,4 @@ -// Copyright 2013, Örjan Persson. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//+build windows plan9 - -package logging +package logger import ( "fmt" diff --git a/example_test.go b/tests/example_test.go similarity index 98% rename from example_test.go rename to tests/example_test.go index 52fd733..530fed3 100644 --- a/example_test.go +++ b/tests/example_test.go @@ -1,4 +1,4 @@ -package logging +package logger import "os" diff --git a/format_test.go b/tests/format_test.go similarity index 93% rename from format_test.go rename to tests/format_test.go index c008e9e..3c74863 100644 --- a/format_test.go +++ b/tests/format_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import ( "bytes" @@ -109,14 +109,14 @@ func TestFormatFuncName(t *testing.T) { "main", "main", "main"}, - {"github.com/op/go-logging.func·001", - "github.com/op/go-logging", - "go-logging", + {"mimirtech.net/gitea/GoUtilities/logger.func·001", + "mimirtech.net/gitea/GoUtilities/logger", + "logger", "func·001", "func·001"}, - {"github.com/op/go-logging.stringFormatter.Format", - "github.com/op/go-logging", - "go-logging", + {"mimirtech.net/gitea/GoUtilities/logger.stringFormatter.Format", + "mimirtech.net/gitea/GoUtilities/logger", + "logger", "stringFormatter.Format", "Format"}, } diff --git a/level_test.go b/tests/level_test.go similarity index 99% rename from level_test.go rename to tests/level_test.go index c8f9a37..a3bab5e 100644 --- a/level_test.go +++ b/tests/level_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import "testing" diff --git a/log_test.go b/tests/log_test.go similarity index 96% rename from log_test.go rename to tests/log_test.go index c7a645f..08e969d 100644 --- a/log_test.go +++ b/tests/log_test.go @@ -1,8 +1,4 @@ -// Copyright 2013, Örjan Persson. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package logging +package logger import ( "bytes" diff --git a/logger_test.go b/tests/logger_test.go similarity index 99% rename from logger_test.go rename to tests/logger_test.go index b9f7fe7..f2209c3 100644 --- a/logger_test.go +++ b/tests/logger_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import "testing" diff --git a/memory_test.go b/tests/memory_test.go similarity index 99% rename from memory_test.go rename to tests/memory_test.go index c2fe6c8..7c6759d 100644 --- a/memory_test.go +++ b/tests/memory_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import ( "strconv" diff --git a/multi_test.go b/tests/multi_test.go similarity index 98% rename from multi_test.go rename to tests/multi_test.go index e1da5e3..a0436a3 100644 --- a/multi_test.go +++ b/tests/multi_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package logging +package logger import "testing"