Remove logrus to allow for easier customization
This commit is contained in:
@@ -22,8 +22,6 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func lookupMQM() (int, int, error) {
|
||||
|
||||
@@ -21,8 +21,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// resolveLicenseFile returns the file name of the MQ license file, taking into
|
||||
|
||||
@@ -24,38 +24,19 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/logger"
|
||||
"github.com/ibm-messaging/mq-container/internal/mqini"
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var debug = false
|
||||
|
||||
// timestampFormat matches the format used by MQ messages (includes milliseconds)
|
||||
const timestampFormat string = "2006-01-02T15:04:05.000Z07:00"
|
||||
|
||||
type simpleTextFormatter struct {
|
||||
}
|
||||
|
||||
func (f *simpleTextFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
// If debugging, and a prefix, but only for this formatter.
|
||||
if entry.Level == logrus.DebugLevel {
|
||||
entry.Message = "DEBUG: " + entry.Message
|
||||
}
|
||||
// Use a simple format, with a timestamp
|
||||
return []byte(formatSimple(entry.Time.Format(timestampFormat), entry.Message)), nil
|
||||
}
|
||||
// var debug = false
|
||||
var log *logger.Logger
|
||||
|
||||
func logDebug(args ...interface{}) {
|
||||
if debug {
|
||||
log.Debug(args)
|
||||
}
|
||||
log.Debug(args)
|
||||
}
|
||||
|
||||
func logDebugf(format string, args ...interface{}) {
|
||||
if debug {
|
||||
log.Debugf(format, args...)
|
||||
}
|
||||
log.Debugf(format, args...)
|
||||
}
|
||||
|
||||
func logTerminationf(format string, args ...interface{}) {
|
||||
@@ -94,34 +75,23 @@ func mirrorLogs(ctx context.Context, wg *sync.WaitGroup, name string, fromStart
|
||||
return mirrorLog(ctx, wg, f, fromStart, mf)
|
||||
}
|
||||
|
||||
func configureDebugLogger() {
|
||||
debugEnv, ok := os.LookupEnv("DEBUG")
|
||||
if ok && (debugEnv == "true" || debugEnv == "1") {
|
||||
debug = true
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
logDebug("Debug mode enabled")
|
||||
func getDebug() bool {
|
||||
debug := os.Getenv("DEBUG")
|
||||
if debug == "true" || debug == "1" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func configureLogger() (mirrorFunc, error) {
|
||||
// Set the simple formatter by default
|
||||
log.SetFormatter(new(simpleTextFormatter))
|
||||
f := getLogFormat()
|
||||
d := getDebug()
|
||||
switch f {
|
||||
case "json":
|
||||
formatter := logrus.JSONFormatter{
|
||||
FieldMap: logrus.FieldMap{
|
||||
logrus.FieldKeyMsg: "message",
|
||||
logrus.FieldKeyLevel: "ibm_level",
|
||||
logrus.FieldKeyTime: "ibm_datetime",
|
||||
},
|
||||
TimestampFormat: timestampFormat,
|
||||
}
|
||||
logrus.SetFormatter(&formatter)
|
||||
return func(msg string) {
|
||||
fmt.Println(msg)
|
||||
}, nil
|
||||
log = logger.NewLogger(os.Stdout, d, true)
|
||||
return log.LogDirect, nil
|
||||
case "simple":
|
||||
log = logger.NewLogger(os.Stdout, d, false)
|
||||
return func(msg string) {
|
||||
// Parse the JSON message, and print a simplified version
|
||||
var obj map[string]interface{}
|
||||
@@ -129,6 +99,7 @@ func configureLogger() (mirrorFunc, error) {
|
||||
fmt.Printf(formatSimple(obj["ibm_datetime"].(string), obj["message"].(string)))
|
||||
}, nil
|
||||
default:
|
||||
log = logger.NewLogger(os.Stdout, d, false)
|
||||
return nil, fmt.Errorf("invalid value for LOG_FORMAT: %v", f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/name"
|
||||
"github.com/ibm-messaging/mq-container/internal/ready"
|
||||
)
|
||||
@@ -35,7 +33,6 @@ func doMain() error {
|
||||
logTermination(err)
|
||||
return err
|
||||
}
|
||||
configureDebugLogger()
|
||||
err = ready.Clear()
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
@@ -78,12 +75,12 @@ func doMain() error {
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
defer func() {
|
||||
log.Debugln("Waiting for log mirroring to complete")
|
||||
log.Debug("Waiting for log mirroring to complete")
|
||||
wg.Wait()
|
||||
}()
|
||||
ctx, cancelMirror := context.WithCancel(context.Background())
|
||||
defer func() {
|
||||
log.Debugln("Cancel log mirroring")
|
||||
log.Debug("Cancel log mirroring")
|
||||
cancelMirror()
|
||||
}()
|
||||
// TODO: Use the error channel
|
||||
|
||||
@@ -18,10 +18,11 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/ibm-messaging/mq-container/internal/logger"
|
||||
)
|
||||
|
||||
var test *bool
|
||||
@@ -30,6 +31,7 @@ const filename = "/var/coverage/exitCode"
|
||||
|
||||
func init() {
|
||||
test = flag.Bool("test", false, "Set to true when running tests for coverage")
|
||||
log = logger.NewLogger(os.Stdout, true, false)
|
||||
}
|
||||
|
||||
// Test started when the test binary is started. Only calls main.
|
||||
|
||||
@@ -22,8 +22,6 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// waitForFile waits until the specified file exists
|
||||
@@ -114,7 +112,7 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
||||
// File didn't exist, so need to wait for it
|
||||
fi, err = waitForFile(ctx, path)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
log.Error(err)
|
||||
errorChannel <- err
|
||||
return
|
||||
}
|
||||
@@ -123,7 +121,7 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
||||
}
|
||||
f, err = os.OpenFile(path, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
log.Error(err)
|
||||
errorChannel <- err
|
||||
return
|
||||
}
|
||||
@@ -131,7 +129,7 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
||||
|
||||
fi, err = f.Stat()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
log.Error(err)
|
||||
errorChannel <- err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func TestMirrorLogWithoutRotation(t *testing.T) {
|
||||
@@ -191,8 +189,3 @@ func TestMirrorLogCancelWhileWaiting(t *testing.T) {
|
||||
wg.Wait()
|
||||
// No need to assert anything. If it didn't work, the code would have hung (TODO: not ideal)
|
||||
}
|
||||
|
||||
func init() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.SetFormatter(new(simpleTextFormatter))
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/capabilities"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func logBaseImage() error {
|
||||
@@ -73,7 +72,7 @@ func readProc(filename string) (value string, err error) {
|
||||
func readMounts() error {
|
||||
all, err := readProc("/proc/mounts")
|
||||
if err != nil {
|
||||
log.Println("Error: Couldn't read /proc/mounts")
|
||||
log.Print("Error: Couldn't read /proc/mounts")
|
||||
return err
|
||||
}
|
||||
lines := strings.Split(all, "\n")
|
||||
@@ -89,7 +88,7 @@ func readMounts() error {
|
||||
}
|
||||
}
|
||||
if !detected {
|
||||
log.Println("No volume detected. Persistent messages may be lost")
|
||||
log.Print("No volume detected. Persistent messages may be lost")
|
||||
} else {
|
||||
checkFS("/mnt/mqm")
|
||||
}
|
||||
@@ -102,14 +101,14 @@ func logConfig() {
|
||||
var err error
|
||||
osr, err := readProc("/proc/sys/kernel/osrelease")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Print(err)
|
||||
} else {
|
||||
log.Printf("Linux kernel version: %v", osr)
|
||||
}
|
||||
logBaseImage()
|
||||
fileMax, err := readProc("/proc/sys/fs/file-max")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Print(err)
|
||||
} else {
|
||||
log.Printf("Maximum file handles: %v", fileMax)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/command"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// createDirStructure creates the default MQ directory structure under /var/mqm
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user