-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8958eab
commit 628ae03
Showing
15 changed files
with
302 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Package color provides a list of escape sequences to output colored text to terminal | ||
package color | ||
|
||
import "io" | ||
|
||
const ( | ||
None = "" | ||
Reset = "\033[0m" | ||
Bold = "\033[1m" | ||
Red = "\033[31m" | ||
Green = "\033[32m" | ||
Yellow = "\033[33m" | ||
Blue = "\033[34m" | ||
Purple = "\033[35m" | ||
Cyan = "\033[36m" | ||
Gray = "\033[37m" | ||
White = "\033[97m" | ||
) | ||
|
||
func Apply(writer io.StringWriter, color string, do func()) { | ||
if color == None { | ||
do() | ||
return | ||
} | ||
|
||
writer.WriteString(color) | ||
|
||
do() | ||
|
||
writer.WriteString(Reset) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package log | ||
|
||
import "github.com/thehungry-dev/cog" | ||
|
||
func LogTextExample() cog.Writer { | ||
return cog.TagsWriter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package message | ||
|
||
import ( | ||
tagfilterctrls "github.com/thehungry-dev/cog/ctrls/tag/filter" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Package device provides different kind of devices valid for log output | ||
package device | ||
|
||
import "io" | ||
|
||
var Null io.StringWriter | ||
|
||
type nullStringWriter struct{} | ||
|
||
func (nullStringWriter) WriteString(_ string) (int, error) { return 0, nil } | ||
|
||
func init() { | ||
Null = nullStringWriter{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= | ||
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= | ||
github.com/thehungry-dev/asserting v0.2.0 h1:hgQgVuRR7zUOSF547H0MQ2JvZdAwxLIC2f9cukQMCl4= | ||
github.com/thehungry-dev/asserting v0.2.0/go.mod h1:rwslLo/jyrmtsHYm8f9YIuI2qKwUQAQUR/oCz1jeN6A= | ||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= | ||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
// Package transform converts a build message into different formats | ||
package transform | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/thehungry-dev/cog/paint" | ||
) | ||
|
||
type Config struct { | ||
Timestamp bool | ||
Tags bool | ||
Level bool | ||
Fields bool | ||
Timestamp bool | ||
Tags bool | ||
Level bool | ||
Fields bool | ||
BuildPainter func(io.StringWriter) paint.Painter | ||
} | ||
|
||
var DefaultConfig Config | ||
var EverythingConfig Config | ||
|
||
func init() { | ||
DefaultConfig = Config{ | ||
Timestamp: true, | ||
Tags: false, | ||
Level: true, | ||
Fields: true, | ||
Timestamp: true, | ||
Tags: false, | ||
Level: true, | ||
Fields: true, | ||
BuildPainter: paint.NewFullPainter, | ||
} | ||
|
||
EverythingConfig = Config{ | ||
Timestamp: true, | ||
Tags: true, | ||
Level: true, | ||
Fields: true, | ||
Timestamp: true, | ||
Tags: true, | ||
Level: true, | ||
Fields: true, | ||
BuildPainter: paint.NewFullPainter, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package paint | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/thehungry-dev/cog/color" | ||
"github.com/thehungry-dev/cog/message" | ||
) | ||
|
||
type fullPainter struct { | ||
buf io.StringWriter | ||
styled bool | ||
} | ||
|
||
func NewFullPainter(buf io.StringWriter) Painter { | ||
return &fullPainter{buf: buf, styled: false} | ||
} | ||
|
||
func (painter *fullPainter) BeginMessage(msg message.Message) { | ||
clr := Color(msg.Level) | ||
|
||
painter.styled = clr != color.None | ||
|
||
painter.buf.WriteString(clr) | ||
} | ||
|
||
func (painter *fullPainter) EndMessage(msg message.Message) { | ||
if !painter.styled { | ||
return | ||
} | ||
|
||
painter.styled = false | ||
|
||
painter.buf.WriteString(color.Reset) | ||
} | ||
|
||
func (*fullPainter) BeginTimestamp(_ message.Message) {} | ||
func (*fullPainter) EndTimestamp(_ message.Message) {} | ||
func (*fullPainter) BeginTags(_ message.Message) {} | ||
func (*fullPainter) EndTags(_ message.Message) {} | ||
func (*fullPainter) BeginLevel(_ message.Message) {} | ||
func (*fullPainter) EndLevel(_ message.Message) {} | ||
func (*fullPainter) BeginBody(_ message.Message) {} | ||
func (*fullPainter) EndBody(_ message.Message) {} | ||
func (*fullPainter) BeginFields(_ message.Message) {} | ||
func (*fullPainter) EndFields(_ message.Message) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package paint | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/thehungry-dev/cog/message" | ||
) | ||
|
||
type nullPainter struct{} | ||
|
||
func (nullPainter) BeginMessage(_ message.Message) {} | ||
func (nullPainter) EndMessage(_ message.Message) {} | ||
func (nullPainter) BeginTimestamp(_ message.Message) {} | ||
func (nullPainter) EndTimestamp(_ message.Message) {} | ||
func (nullPainter) BeginTags(_ message.Message) {} | ||
func (nullPainter) EndTags(_ message.Message) {} | ||
func (nullPainter) BeginLevel(_ message.Message) {} | ||
func (nullPainter) EndLevel(_ message.Message) {} | ||
func (nullPainter) BeginBody(_ message.Message) {} | ||
func (nullPainter) EndBody(_ message.Message) {} | ||
func (nullPainter) BeginFields(_ message.Message) {} | ||
func (nullPainter) EndFields(_ message.Message) {} | ||
|
||
func NewNullPainter(_ io.StringWriter) Painter { return NullPainter } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package paint provides an interface to set terminal output colors for parts or the entirety of a log message | ||
package paint | ||
|
||
import ( | ||
"github.com/thehungry-dev/cog/color" | ||
"github.com/thehungry-dev/cog/level" | ||
"github.com/thehungry-dev/cog/message" | ||
) | ||
|
||
type Painter interface { | ||
BeginMessage(msg message.Message) | ||
EndMessage(msg message.Message) | ||
BeginTimestamp(msg message.Message) | ||
EndTimestamp(msg message.Message) | ||
BeginTags(msg message.Message) | ||
EndTags(msg message.Message) | ||
BeginLevel(msg message.Message) | ||
EndLevel(msg message.Message) | ||
BeginBody(msg message.Message) | ||
EndBody(msg message.Message) | ||
BeginFields(msg message.Message) | ||
EndFields(msg message.Message) | ||
} | ||
|
||
var NullPainter Painter | ||
|
||
func Color(lvl level.Level) string { | ||
clr, ok := palette[lvl] | ||
|
||
if !ok { | ||
return color.None | ||
} | ||
|
||
return clr | ||
} | ||
|
||
func init() { | ||
NullPainter = nullPainter{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package paint | ||
|
||
import ( | ||
"github.com/thehungry-dev/cog/color" | ||
"github.com/thehungry-dev/cog/level" | ||
) | ||
|
||
var palette map[level.Level]string | ||
|
||
func init() { | ||
palette = make(map[level.Level]string, 6) | ||
palette[level.Trace] = color.None | ||
palette[level.Debug] = color.Green | ||
palette[level.Info] = color.White | ||
palette[level.Warn] = color.Yellow | ||
palette[level.Error] = color.Red | ||
palette[level.Fatal] = color.Red + color.Bold | ||
} |
Oops, something went wrong.