Changing up the flow of the logging system, starting to move the tests
into their own directory for organization.
This commit is contained in:
parent
81f03c7d07
commit
d346733b9b
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
// defaultBackend is the backend used for all logging calls.
|
// defaultBackend is the backend used for all logging calls.
|
||||||
var defaultBackend LeveledBackend
|
var defaultBackend LeveledBackend
|
||||||
|
|||||||
@ -2,14 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"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
|
// Example format string. Everything except the message has a custom color
|
||||||
// which is dependent on the log level. Many fields have a custom output
|
// 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.
|
// 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}`,
|
`%{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
|
type Password string
|
||||||
|
|
||||||
func (p Password) Redacted() interface{} {
|
func (p Password) Redacted() interface{} {
|
||||||
return logging.Redact(string(p))
|
return logger.Redact(string(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// For demo purposes, create two backend for os.Stderr.
|
// For demo purposes, create two backend for os.Stderr.
|
||||||
backend1 := logging.NewLogBackend(os.Stderr, "", 0)
|
backend1 := logger.NewLogBackend(os.Stderr, "", 0)
|
||||||
backend2 := logging.NewLogBackend(os.Stderr, "", 0)
|
backend2 := logger.NewLogBackend(os.Stderr, "", 0)
|
||||||
|
|
||||||
// For messages written to backend2 we want to add some additional
|
// For messages written to backend2 we want to add some additional
|
||||||
// information to the output, including the used log level and the name of
|
// information to the output, including the used log level and the name of
|
||||||
// the function.
|
// the function.
|
||||||
backend2Formatter := logging.NewBackendFormatter(backend2, format)
|
backend2Formatter := logger.NewBackendFormatter(backend2, format)
|
||||||
|
|
||||||
// Only errors and more severe messages should be sent to backend1
|
// Only errors and more severe messages should be sent to backend1
|
||||||
backend1Leveled := logging.AddModuleLevel(backend1)
|
backend1Leveled := logger.AddModuleLevel(backend1)
|
||||||
backend1Leveled.SetLevel(logging.ERROR, "")
|
backend1Leveled.SetLevel(logger.ERROR, "")
|
||||||
|
|
||||||
// Set the backends to be used.
|
// Set the backends to be used.
|
||||||
logging.SetBackend(backend1Leveled, backend2Formatter)
|
logger.SetBackend(backend1Leveled, backend2Formatter)
|
||||||
|
|
||||||
log.Debugf("debug %s", Password("secret"))
|
log.Debugf("debug %s", Password("secret"))
|
||||||
log.Info("info")
|
log.Info("info")
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -191,8 +191,8 @@ type stringFormatter struct {
|
|||||||
// future.
|
// future.
|
||||||
//
|
//
|
||||||
// Experimental:
|
// Experimental:
|
||||||
// %{longpkg} Full package path, eg. github.com/go-logging
|
// %{longpkg} Full package path, eg. mimirtech.net/gitea/GoUtilities/logger
|
||||||
// %{shortpkg} Base package path, eg. go-logging
|
// %{shortpkg} Base package path, eg. logger
|
||||||
// %{longfunc} Full function name, eg. littleEndian.PutUint32
|
// %{longfunc} Full function name, eg. littleEndian.PutUint32
|
||||||
// %{shortfunc} Base function name, eg. PutUint32
|
// %{shortfunc} Base function name, eg. PutUint32
|
||||||
// %{callpath} Call function path, eg. main.a.b.c
|
// %{callpath} Call function path, eg. main.a.b.c
|
||||||
|
|||||||
2
level.go
2
level.go
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
// +build !windows
|
package logger
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
// Package logging implements a logging infrastructure for Go. It supports
|
// Package logging implements a logging infrastructure for Go. It supports
|
||||||
// different logging backends like syslog, file and memory. Multiple backends
|
// different logging backends like syslog, file and memory. Multiple backends
|
||||||
// can be utilized with different log levels per backend and logger.
|
// can be utilized with different log levels per backend and logger.
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
// Copyright 2013, Örjan Persson. All rights reserved.
|
package logger
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package logging
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|||||||
6
multi.go
6
multi.go
@ -1,8 +1,4 @@
|
|||||||
// Copyright 2013, Örjan Persson. All rights reserved.
|
package logger
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package logging
|
|
||||||
|
|
||||||
// TODO remove Level stuff from the multi logger. Do one thing.
|
// TODO remove Level stuff from the multi logger. Do one thing.
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
// Copyright 2013, Örjan Persson. All rights reserved.
|
package logger
|
||||||
// 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
|
|
||||||
|
|
||||||
import "log/syslog"
|
import "log/syslog"
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
// Copyright 2013, Örjan Persson. All rights reserved.
|
package logger
|
||||||
// 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
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package logging
|
package logger
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -109,14 +109,14 @@ func TestFormatFuncName(t *testing.T) {
|
|||||||
"main",
|
"main",
|
||||||
"main",
|
"main",
|
||||||
"main"},
|
"main"},
|
||||||
{"github.com/op/go-logging.func·001",
|
{"mimirtech.net/gitea/GoUtilities/logger.func·001",
|
||||||
"github.com/op/go-logging",
|
"mimirtech.net/gitea/GoUtilities/logger",
|
||||||
"go-logging",
|
"logger",
|
||||||
"func·001",
|
"func·001",
|
||||||
"func·001"},
|
"func·001"},
|
||||||
{"github.com/op/go-logging.stringFormatter.Format",
|
{"mimirtech.net/gitea/GoUtilities/logger.stringFormatter.Format",
|
||||||
"github.com/op/go-logging",
|
"mimirtech.net/gitea/GoUtilities/logger",
|
||||||
"go-logging",
|
"logger",
|
||||||
"stringFormatter.Format",
|
"stringFormatter.Format",
|
||||||
"Format"},
|
"Format"},
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
@ -1,8 +1,4 @@
|
|||||||
// Copyright 2013, Örjan Persson. All rights reserved.
|
package logger
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package logging
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package logging
|
package logger
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user