GODT-1779: Remove go-imap

This commit is contained in:
James Houlahan
2022-08-26 17:00:21 +02:00
parent 3b0bc1ca15
commit 39433fe707
593 changed files with 12725 additions and 91626 deletions

View File

@ -45,12 +45,13 @@ const (
MaxLogs = 3
)
func Init(logsPath string) error {
func Init(logsPath, level string) error {
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: time.StampMilli,
})
logrus.AddHook(&writer.Hook{
Writer: os.Stderr,
LogLevels: []logrus.Level{
@ -74,24 +75,34 @@ func Init(logsPath string) error {
}
logrus.SetOutput(rotator)
return nil
return setLevel(level)
}
// SetLevel will change the level of logging and in case of Debug or Trace
// setLevel will change the level of logging and in case of Debug or Trace
// level it will also prevent from writing to file. Setting level to Info or
// higher will not set writing to file again if it was previously cancelled by
// Debug or Trace.
func SetLevel(level string) {
if lvl, err := logrus.ParseLevel(level); err == nil {
logrus.SetLevel(lvl)
func setLevel(level string) error {
if level == "" {
return nil
}
logLevel, err := logrus.ParseLevel(level)
if err != nil {
return err
}
logrus.SetLevel(logLevel)
// The hook to print panic, fatal and error to stderr is always
// added. We want to avoid log duplicates by replacing all hooks.
if logrus.GetLevel() == logrus.DebugLevel || logrus.GetLevel() == logrus.TraceLevel {
// The hook to print panic, fatal and error to stderr is always
// added. We want to avoid log duplicates by replacing all hooks
_ = logrus.StandardLogger().ReplaceHooks(logrus.LevelHooks{})
logrus.SetOutput(os.Stderr)
}
return nil
}
func getLogName(version, revision string) string {

View File

@ -27,8 +27,7 @@ import (
// TestClearLogs tests that cearLogs removes only bridge old log files keeping last three of them.
func TestClearLogs(t *testing.T) {
dir, err := os.MkdirTemp("", "clear-logs-test")
require.NoError(t, err)
dir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(dir, "other.log"), []byte("Hello"), 0o755))
require.NoError(t, os.WriteFile(filepath.Join(dir, "v1_10.log"), []byte("Hello"), 0o755))

View File

@ -75,23 +75,8 @@ func TestRotator(t *testing.T) {
assert.Equal(t, 4, n)
}
func BenchmarkRotateRAMFile(b *testing.B) {
dir, err := os.MkdirTemp("", "rotate-benchmark")
require.NoError(b, err)
defer os.RemoveAll(dir) //nolint:errcheck
benchRotate(b, MaxLogSize, getTestFile(b, dir, MaxLogSize-1))
}
func BenchmarkRotateDiskFile(b *testing.B) {
cache, err := os.UserCacheDir()
require.NoError(b, err)
dir, err := os.MkdirTemp(cache, "rotate-benchmark")
require.NoError(b, err)
defer os.RemoveAll(dir) //nolint:errcheck
benchRotate(b, MaxLogSize, getTestFile(b, dir, MaxLogSize-1))
func BenchmarkRotate(b *testing.B) {
benchRotate(b, MaxLogSize, getTestFile(b, b.TempDir(), MaxLogSize-1))
}
func benchRotate(b *testing.B, logSize int, getFile func() (io.WriteCloser, error)) {