Permalink
Browse files

move LevelNone to the highest level

Signed-off-by: Peter Edge <peter.edge@gmail.com>
  • Loading branch information...
peter-edge committed Jan 27, 2016
1 parent e8d163c commit ffa4c72de90ddc168ad6df1c585880f174e83664
Showing with 144 additions and 125 deletions.
  1. +11 −10 lion_level.go
  2. +1 −1 logger.go
  3. +2 −2 proto/marshal.go
  4. +46 −46 proto/protolion.pb.go
  5. +7 −8 proto/protolion.proto
  6. +1 −1 syslog/pusher.go
  7. +76 −57 testing/testing_test.go
View
@@ -6,40 +6,41 @@ import (
)
const (
// LevelNone represents no Level.
LevelNone Level = 0
// LevelDebug is the debug Level.
LevelDebug Level = 1
LevelDebug Level = 0
// LevelInfo is the info Level.
LevelInfo Level = 2
LevelInfo Level = 1
// LevelWarn is the warn Level.
LevelWarn Level = 3
LevelWarn Level = 2
// LevelError is the error Level.
LevelError Level = 4
LevelError Level = 3
// LevelFatal is the fatal Level.
LevelFatal Level = 5
LevelFatal Level = 4
// LevelPanic is the panic Level.
LevelPanic Level = 6
LevelPanic Level = 5
// LevelNone represents no Level.
// It is always logged.
LevelNone Level = 6
)
var (
levelToName = map[Level]string{
LevelNone: "NONE",
LevelDebug: "DEBUG",
LevelInfo: "INFO",
LevelWarn: "WARN",
LevelError: "ERROR",
LevelFatal: "FATAL",
LevelPanic: "PANIC",
LevelNone: "NONE",
}
nameToLevel = map[string]Level{
"NONE": LevelNone,
"DEBUG": LevelDebug,
"INFO": LevelInfo,
"WARN": LevelWarn,
"ERROR": LevelError,
"FATAL": LevelFatal,
"PANIC": LevelPanic,
"NONE": LevelNone,
}
)
View
@@ -268,7 +268,7 @@ func (l *logger) printWithError(level Level, event *EntryMessage, message string
}
func (l *logger) isLoggedLevel(level Level) bool {
return level >= l.level || level == LevelNone
return level >= l.level
}
type logWriter struct {
View
@@ -13,22 +13,22 @@ import (
var (
levelToProto = map[lion.Level]Level{
lion.LevelNone: Level_LEVEL_NONE,
lion.LevelDebug: Level_LEVEL_DEBUG,
lion.LevelInfo: Level_LEVEL_INFO,
lion.LevelWarn: Level_LEVEL_WARN,
lion.LevelError: Level_LEVEL_ERROR,
lion.LevelFatal: Level_LEVEL_FATAL,
lion.LevelPanic: Level_LEVEL_PANIC,
lion.LevelNone: Level_LEVEL_NONE,
}
protoToLevel = map[Level]lion.Level{
Level_LEVEL_NONE: lion.LevelNone,
Level_LEVEL_DEBUG: lion.LevelDebug,
Level_LEVEL_INFO: lion.LevelInfo,
Level_LEVEL_WARN: lion.LevelWarn,
Level_LEVEL_ERROR: lion.LevelError,
Level_LEVEL_FATAL: lion.LevelFatal,
Level_LEVEL_PANIC: lion.LevelPanic,
Level_LEVEL_NONE: lion.LevelNone,
}
)
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,14 +8,13 @@ option go_package = "protolion";
// Level is a logging level.
enum Level {
// is valid
LEVEL_NONE = 0;
LEVEL_DEBUG = 1;
LEVEL_INFO = 2;
LEVEL_WARN = 3;
LEVEL_ERROR = 4;
LEVEL_FATAL = 5;
LEVEL_PANIC = 6;
LEVEL_DEBUG = 0;
LEVEL_INFO = 1;
LEVEL_WARN = 2;
LEVEL_ERROR = 3;
LEVEL_FATAL = 4;
LEVEL_PANIC = 5;
LEVEL_NONE = 6;
}
// Entry is the object serialized for logging.
View
@@ -8,13 +8,13 @@ import (
var (
levelToLogFunc = map[lion.Level]func(*syslog.Writer, string) error{
lion.LevelNone: (*syslog.Writer).Info,
lion.LevelDebug: (*syslog.Writer).Debug,
lion.LevelInfo: (*syslog.Writer).Info,
lion.LevelWarn: (*syslog.Writer).Warning,
lion.LevelError: (*syslog.Writer).Err,
lion.LevelFatal: (*syslog.Writer).Crit,
lion.LevelPanic: (*syslog.Writer).Alert,
lion.LevelNone: (*syslog.Writer).Info,
}
)
View
@@ -16,6 +16,80 @@ import (
)
func TestRoundtripAndTextMarshaller(t *testing.T) {
testRoundTripAndTextMarshaller(
t,
func(logger protolion.Logger) {
logger.Debug(
&Foo{
StringField: "one",
Int32Field: 2,
},
)
logger.Info(
&Baz{
Bat: &Baz_Bat{
Ban: &Baz_Bat_Ban{
StringField: "one",
Int32Field: 2,
},
},
},
)
logger.Info(&Empty{})
logger.Info(&NoStdJson{
One: map[uint64]string{
1: "one",
2: "two",
},
})
writer := logger.InfoWriter()
for _, s := range []string{
"hello",
"world",
"writing",
"strings",
"is",
"fun",
} {
_, _ = writer.Write([]byte(s))
}
writer = logger.Writer()
_, _ = writer.Write([]byte("none"))
logger.Infoln("a normal line")
logger.WithField("someKey", "someValue").Warnln("a warning line")
},
`DEBUG lion.testing.Foo {"one":"","two":0,"string_field":"one","int32_field":2}
INFO lion.testing.Baz {"bat":{"ban":{"string_field":"one","int32_field":2}}}
INFO lion.testing.Empty {}
INFO lion.testing.NoStdJson {"one":{"1":"one","2":"two"}}
INFO hello
INFO world
INFO writing
INFO strings
INFO is
INFO fun
NONE none
INFO a normal line
WARN a warning line {"someKey":"someValue"}
`,
)
}
func TestLevelNone(t *testing.T) {
testRoundTripAndTextMarshaller(
t,
func(logger protolion.Logger) {
logger = logger.AtLevel(lion.LevelPanic)
logger.Errorln("hello")
logger.Println("hello")
logger = logger.AtLevel(lion.LevelNone)
logger.Println("hello2")
},
"NONE hello\nNONE hello2\n",
)
}
func testRoundTripAndTextMarshaller(t *testing.T, f func(protolion.Logger), expected string) {
buffer := bytes.NewBuffer(nil)
fakeTimer := newFakeTimer(0)
logger := protolion.NewLogger(
@@ -28,45 +102,7 @@ func TestRoundtripAndTextMarshaller(t *testing.T) {
lion.LoggerWithTimer(fakeTimer),
).AtLevel(lion.LevelDebug),
)
logger.Debug(
&Foo{
StringField: "one",
Int32Field: 2,
},
)
logger.Info(
&Baz{
Bat: &Baz_Bat{
Ban: &Baz_Bat_Ban{
StringField: "one",
Int32Field: 2,
},
},
},
)
logger.Info(&Empty{})
logger.Info(&NoStdJson{
One: map[uint64]string{
1: "one",
2: "two",
},
})
writer := logger.InfoWriter()
for _, s := range []string{
"hello",
"world",
"writing",
"strings",
"is",
"fun",
} {
_, _ = writer.Write([]byte(s))
}
writer = logger.Writer()
_, _ = writer.Write([]byte("none"))
logger.Infoln("a normal line")
logger.WithField("someKey", "someValue").Warnln("a warning line")
f(logger)
puller := lion.NewReadPuller(
buffer,
protolion.DelimitedUnmarshaller,
@@ -82,24 +118,7 @@ func TestRoundtripAndTextMarshaller(t *testing.T) {
require.NoError(t, err)
require.NoError(t, writePusher.Push(entry))
}
require.Equal(
t,
`DEBUG lion.testing.Foo {"one":"","two":0,"string_field":"one","int32_field":2}
INFO lion.testing.Baz {"bat":{"ban":{"string_field":"one","int32_field":2}}}
INFO lion.testing.Empty {}
INFO lion.testing.NoStdJson {"one":{"1":"one","2":"two"}}
INFO hello
INFO world
INFO writing
INFO strings
INFO is
INFO fun
NONE none
INFO a normal line
WARN a warning line {"someKey":"someValue"}
`,
writeBuffer.String(),
)
require.Equal(t, expected, writeBuffer.String())
}
func TestPrintSomeStuff(t *testing.T) {

0 comments on commit ffa4c72

Please sign in to comment.