From 2a6224532ba48ad35c08846251fb8e4cb4a29238 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 19 Jan 2020 16:14:59 +0000 Subject: [PATCH] outlining stuff --- codec.go | 6 ++++++ event.go | 27 +++++++++++++++++++++++++++ go.mod | 2 ++ go.sum | 8 ++++++++ json.go | 4 ++++ level.go | 23 +++++++++++++++++++++++ line.go | 4 ++++ path.go | 3 +++ path_test.go | 3 +++ tag.go | 7 +++++++ text.go | 4 ++++ writer.go | 5 +++++ 12 files changed, 96 insertions(+) create mode 100644 codec.go create mode 100644 event.go create mode 100644 go.sum create mode 100644 json.go create mode 100644 level.go create mode 100644 line.go create mode 100644 tag.go create mode 100644 text.go create mode 100644 writer.go diff --git a/codec.go b/codec.go new file mode 100644 index 0000000..66f80c1 --- /dev/null +++ b/codec.go @@ -0,0 +1,6 @@ +package blammo + +type Codec interface { + Encode(*Event, []byte) error + Decode(*Event, []byte) error +} diff --git a/event.go b/event.go new file mode 100644 index 0000000..a81fdd6 --- /dev/null +++ b/event.go @@ -0,0 +1,27 @@ +package blammo + +import ( + "time" +) + +// Event is a single log record. A log line if you're writing to file, a +// database row if you're writing to a database, etc. Everything internally is +// expressed as an event. +// +// Event is exported to support the implementation of custom log writers. +type Event struct { + // severity of the event + Level Level + + // time at which the event occured + Time time.Time + + // where the event occurred in the system + Path *Path + + // message to be logged + Text string + + // key-value pairs to log as extra metadata + Tags *Tags +} diff --git a/go.mod b/go.mod index cd4ba66..a91df0e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/jordanorelli/blammo go 1.13 + +require golang.org/x/crypto v0.0.0-20200117160349-530e935923ad // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3474575 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= +golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/json.go b/json.go new file mode 100644 index 0000000..4dfa0b4 --- /dev/null +++ b/json.go @@ -0,0 +1,4 @@ +package blammo + +type JSONWriter struct { +} diff --git a/level.go b/level.go new file mode 100644 index 0000000..da95d09 --- /dev/null +++ b/level.go @@ -0,0 +1,23 @@ +package blammo + +type Level uint + +const ( + // Debug is intended to be used for verbose logging information of + // implementation details. + Debug Level = iota + + // Info is intended to be used to report expected behaviors; it's used to + // log usage and observe normal behaviors. + Info + + // Warn is intended to be used to report events that are not along the + // expected "happy path" of the application. These events should generally + // represent failures of -other- systems. + Warn + + // Error is intended to b e used to report things that the application was + // not able to handle. These events should generally represent failures of + // the system at hand. + Error +) diff --git a/line.go b/line.go new file mode 100644 index 0000000..f357b29 --- /dev/null +++ b/line.go @@ -0,0 +1,4 @@ +package blammo + +type LineWriter struct { +} diff --git a/path.go b/path.go index 10068fd..2ccb3d9 100644 --- a/path.go +++ b/path.go @@ -39,6 +39,9 @@ func (p *Path) String() string { // Child creates a child path having parent p. This is the recommended way of // constructing a hierarchical path. func (p *Path) Child(name string) *Path { + if name == "" { + name = "-" + } return &Path{ name: MakeSafeName(name), parent: p, diff --git a/path_test.go b/path_test.go index 0ae4ce0..fcf060d 100644 --- a/path_test.go +++ b/path_test.go @@ -56,6 +56,9 @@ func TestSafeNames(t *testing.T) { "one ", "alice/bob", "alice bob", + "alice[bob]", + "alice{bob}", + "alice=bob", } for _, n := range unsafeNames { if IsSafeName(n) { diff --git a/tag.go b/tag.go new file mode 100644 index 0000000..0692b8b --- /dev/null +++ b/tag.go @@ -0,0 +1,7 @@ +package blammo + +type Tags struct { + key string + value interface{} + parent *Tags +} diff --git a/text.go b/text.go new file mode 100644 index 0000000..79f7a46 --- /dev/null +++ b/text.go @@ -0,0 +1,4 @@ +package blammo + +type TextWriter struct { +} diff --git a/writer.go b/writer.go new file mode 100644 index 0000000..293aa53 --- /dev/null +++ b/writer.go @@ -0,0 +1,5 @@ +package blammo + +type EventWriter interface { + WriteEvent(*Event) error +}