Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyConsoleColor(s string, level int, c ConsoleColorTheme) string
- func ApplyHTMLColor(s string, level int, c HTMLColorTheme) string
- func ConsoleWrite(t *Transport, s string)
- func FileWrite(t *Transport, s string)
- func LevelToString(level int) string
- func Log(args ...interface{})
- type ConsoleColorAspect
- type ConsoleColorTheme
- type HTMLColorAspect
- type HTMLColorTheme
- type JSONFormatted
- type Logger
- func (l *Logger) AddTime(layout string)
- func (l *Logger) AddTransport(t int, param ...interface{}) *Transport
- func (l *Logger) AttachFunction(level int, function func(string))
- func (l *Logger) Critical(args ...interface{})
- func (l *Logger) CriticalF(s string, args ...interface{})
- func (l *Logger) CriticalNR(args ...interface{})
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) DebugF(s string, args ...interface{})
- func (l *Logger) DebugNR(args ...interface{})
- func (l *Logger) DisableAllLevels() *Logger
- func (l *Logger) DisableLevel(level int) *Logger
- func (l *Logger) EnableAllLevels() *Logger
- func (l *Logger) EnableLevel(level int) *Logger
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) ErrorF(s string, args ...interface{})
- func (l *Logger) ErrorNR(args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) InfoF(s string, args ...interface{})
- func (l *Logger) InfoNR(args ...interface{})
- func (l *Logger) Log(level int, args ...interface{})
- func (l *Logger) LogNR(level int, args ...interface{})
- func (l *Logger) RemoveTime()
- func (l *Logger) SetPrefix(s string) *Logger
- func (l *Logger) SetSuffix(s string) *Logger
- func (l *Logger) Silly(args ...interface{})
- func (l *Logger) SillyF(s string, args ...interface{})
- func (l *Logger) SillyNR(args ...interface{})
- func (l *Logger) Verbose(args ...interface{})
- func (l *Logger) VerboseF(s string, args ...interface{})
- func (l *Logger) VerboseNR(args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) WarnF(s string, args ...interface{})
- func (l *Logger) WarnNR(args ...interface{})
- type Transport
Constants ¶
const ( ConsoleColor = iota HTMLColor = iota )
List of Colors
const ( ConsoleColorDefaultText = "\x1b[39m" ConsoleColorBlackText = "\x1b[30m" ConsoleColorRedText = "\x1b[31m" ConsoleColorGreenText = "\x1b[32m" ConsoleColorYellowText = "\x1b[33m" ConsoleColorBlueText = "\x1b[34m" ConsoleColorMagentaText = "\x1b[35m" ConsoleColorCyanText = "\x1b[36m" ConsoleColorLightGrayText = "\x1b[37m" ConsoleColorDarkGrayText = "\x1b[90m" ConsoleColorLightRedText = "\x1b[91m" ConsoleColorLightGreenText = "\x1b[92m" ConsoleColorLightYellowText = "\x1b[93m" ConsoleColorLightBlueText = "\x1b[94m" ConsoleColorLightMagentaText = "\x1b[95m" ConsoleColorLightCyanText = "\x1b[96m" ConsoleColorWhiteText = "\x1b[97m" )
List of Console Text Colors
const ( ConsoleColorDefaultBackground = "\x1b[49m" ConsoleColorBlackBackground = "\x1b[40m" ConsoleColorRedBackground = "\x1b[41m" ConsoleColorGreenBackground = "\x1b[42m" ConsoleColorYellowBackground = "\x1b[43m" ConsoleColorBlueBackground = "\x1b[44m" ConsoleColorMagentaBackground = "\x1b[45m" ConsoleColorCyanBackground = "\x1b[46m" ConsoleColorLightGrayBackground = "\x1b[47m" ConsoleColorDarkGrayBackground = "\x1b[100m" ConsoleColorLightRedBackground = "\x1b[101m" ConsoleColorLightGreenBackground = "\x1b[102m" ConsoleColorLightYellowBackground = "\x1b[103m" ConsoleColorLightBlueBackground = "\x1b[104m" ConsoleColorLightMagentaBackground = "\x1b[105m" ConsoleColorLightCyanBackground = "\x1b[106m" ConsoleColorWhiteBackground = "\x1b[107m" )
List of Console Background Colors
const ( ConsoleColorBold = "\x1b[1m" ConsoleColorDim = "\x1b[2m" ConsoleColorUnderlined = "\x1b[4m" ConsoleColorBlink = "\x1b[5m" ConsoleColorReverse = "\x1b[7m" ConsoleColorHidden = "\x1b[8m" )
List of Console Text Effects
const ( HTMLColorDefaultText = "deft" HTMLColorBlackText = "blat" HTMLColorRedText = "redt" HTMLColorGreenText = "gret" HTMLColorYellowText = "yelt" HTMLColorBlueText = "blut" HTMLColorMagentaText = "magt" HTMLColorCyanText = "cyat" HTMLColorLightGrayText = "lgrt" HTMLColorDarkGrayText = "dgrt" HTMLColorWhiteText = "whit" )
List of HTML Text Colors
const ( HTMLColorDefaultTextCSS = "black" HTMLColorBlackTextCSS = "black" HTMLColorRedTextCSS = "red" HTMLColorGreenTextCSS = "green" HTMLColorYellowTextCSS = "yellow" HTMLColorBlueTextCSS = "blue" HTMLColorMagentaTextCSS = "magenta" HTMLColorCyanTextCSS = "cyan" HTMLColorLightGrayTextCSS = "lightgray" HTMLColorDarkGrayTextCSS = "darkgray" HTMLColorWhiteTextCSS = "white" )
const ( HTMLColorDefaultBackground = "defbg" HTMLColorBlackBackground = "blabg" HTMLColorRedBackground = "redbg" HTMLColorGreenBackground = "grebg" HTMLColorYellowBackground = "yelbg" HTMLColorBlueBackground = "blubg" HTMLColorMagentaBackground = "magbg" HTMLColorCyanBackground = "cyabg" HTMLColorLightGrayBackground = "lgrbg" HTMLColorDarkGrayBackground = "dgrbg" HTMLColorWhiteBackground = "whibg" )
List of HTML Background Colors
const ( HTMLColorDefaultBackgroundCSS = "LightSteelBlue" HTMLColorBlackBackgroundCSS = "black" HTMLColorRedBackgroundCSS = "red" HTMLColorGreenBackgroundCSS = "green" HTMLColorYellowBackgroundCSS = "yellow" HTMLColorBlueBackgroundCSS = "blue" HTMLColorMagentaBackgroundCSS = "magenta" HTMLColorCyanBackgroundCSS = "cyan" HTMLColorLightGrayBackgroundCSS = "lightgray" HTMLColorDarkGrayBackgroundCSS = "darkgray" HTMLColorWhiteBackgroundCSS = "white" )
const ( HTMLColorBold = "bold" HTMLColorBolder = "bolder" HTMLColorUnderlined = "underln" HTMLColorItalic = "italic" )
List of HTML Text Effects
const ( Silly = iota Debug = iota Verbose = iota Info = iota Warn = iota Error = iota Critical = iota )
List of logging levels
const ( Console = iota File = iota )
List of transports
Variables ¶
var ( HTMLColorHeader string = ` <style> *{background-color: ` + HTMLColorDefaultBackgroundCSS + `;} .` + HTMLColorDefaultText + `{color: ` + HTMLColorDefaultTextCSS + `;} .` + HTMLColorBlackText + `{color: ` + HTMLColorBlackTextCSS + `;} .` + HTMLColorRedText + `{color: ` + HTMLColorRedTextCSS + `;} .` + HTMLColorGreenText + `{color: ` + HTMLColorGreenTextCSS + `;} .` + HTMLColorYellowText + `{color: ` + HTMLColorYellowTextCSS + `;} .` + HTMLColorBlueText + `{color: ` + HTMLColorBlueTextCSS + `;} .` + HTMLColorMagentaText + `{color: ` + HTMLColorMagentaTextCSS + `;} .` + HTMLColorCyanText + `{color: ` + HTMLColorCyanTextCSS + `;} .` + HTMLColorLightGrayText + `{color: ` + HTMLColorLightGrayTextCSS + `;} .` + HTMLColorDarkGrayText + `{color: ` + HTMLColorDarkGrayTextCSS + `;} .` + HTMLColorWhiteText + `{color: ` + HTMLColorWhiteTextCSS + `;} .` + HTMLColorDefaultBackground + `{background-color: ` + HTMLColorDefaultBackgroundCSS + `;display:inline;} .` + HTMLColorBlackBackground + `{background-color: ` + HTMLColorBlackBackgroundCSS + `;display:inline;} .` + HTMLColorRedBackground + `{background-color: ` + HTMLColorRedBackgroundCSS + `;display:inline;} .` + HTMLColorGreenBackground + `{background-color: ` + HTMLColorGreenBackgroundCSS + `;display:inline;} .` + HTMLColorYellowBackground + `{background-color: ` + HTMLColorYellowBackgroundCSS + `;display:inline;} .` + HTMLColorBlueBackground + `{background-color: ` + HTMLColorBlueBackgroundCSS + `;display:inline;} .` + HTMLColorMagentaBackground + `{background-color: ` + HTMLColorMagentaBackgroundCSS + `;display:inline;} .` + HTMLColorCyanBackground + `{background-color: ` + HTMLColorCyanBackgroundCSS + `;display:inline;} .` + HTMLColorLightGrayBackground + `{background-color: ` + HTMLColorLightGrayBackgroundCSS + `;display:inline;} .` + HTMLColorDarkGrayBackground + `{background-color: ` + HTMLColorDarkGrayBackgroundCSS + `;display:inline;} .` + HTMLColorWhiteBackground + `{background-color: ` + HTMLColorWhiteBackgroundCSS + `;display:inline;} .` + HTMLColorBold + `{font-weight: bold;} .` + HTMLColorBolder + `{font-weight: bolder;} .` + HTMLColorUnderlined + `{text-decoration: underline;} .` + HTMLColorItalic + `{font-style: italic;} </style> ` )
HTML Header for CSS
Functions ¶
func ApplyConsoleColor ¶
func ApplyConsoleColor(s string, level int, c ConsoleColorTheme) string
Apply a color theme on a string with the corect logging level
func ApplyHTMLColor ¶
func ApplyHTMLColor(s string, level int, c HTMLColorTheme) string
Apply a color theme on a string with the corect logging level
func LevelToString ¶
func Log ¶
func Log(args ...interface{})
This function is the simpliest form to write logs with LoGo. It writes variables in the console like fmt.Println()
This function can be rewrite like this:
func Log(args ...interface{}) { fmt.Println(args...) }
But I want to leave the choice of the format to the users. Like replacing: s += fmt.Sprintf("%v ", v) with: s += fmt.Sprintf("%+v ", v) To add struct field names
Types ¶
type ConsoleColorAspect ¶
A Color Aspect describes text and background colors and effects
type ConsoleColorTheme ¶
type ConsoleColorTheme struct { Silly ConsoleColorAspect Debug ConsoleColorAspect Verbose ConsoleColorAspect Info ConsoleColorAspect Warn ConsoleColorAspect Error ConsoleColorAspect Critical ConsoleColorAspect }
A Color Theme is a list of Color Aspect (one for each logging level)
type HTMLColorAspect ¶
A Color Aspect describes text and background colors and effects
type HTMLColorTheme ¶
type HTMLColorTheme struct { Silly HTMLColorAspect Debug HTMLColorAspect Verbose HTMLColorAspect Info HTMLColorAspect Warn HTMLColorAspect Error HTMLColorAspect Critical HTMLColorAspect }
A Color Theme is a list of Color Aspect (one for each logging level)
type JSONFormatted ¶
type JSONFormatted struct { Prefix string `json:"prefix,omitempty"` Suffix string `json:"suffix,omitempty"` Level string `json:"level"` Time string `json:"time,omitempty"` Text string `json:"text"` }
JSON Formatted struct
type Logger ¶
type Logger struct { Transports []Transport Time string Prefix string Suffix string SillyL bool DebugL bool VerboseL bool InfoL bool WarnL bool ErrorL bool CriticalL bool SillyAttachedFunction func(string) DebugAttachedFunction func(string) VerboseAttachedFunction func(string) InfoAttachedFunction func(string) WarnAttachedFunction func(string) ErrorAttachedFunction func(string) CriticalAttachedFunction func(string) }
A Logger struct
func (*Logger) AddTransport ¶
Attach a new Transport to a Logger
func (*Logger) AttachFunction ¶
Attach a function
func (*Logger) CriticalNR ¶
func (l *Logger) CriticalNR(args ...interface{})
func (*Logger) DisableAllLevels ¶
These functions disable or enable logging level :
func (*Logger) DisableLevel ¶
func (*Logger) EnableAllLevels ¶
func (*Logger) EnableLevel ¶
func (*Logger) Silly ¶
func (l *Logger) Silly(args ...interface{})
These functions call Log with the correct logging level :
type Transport ¶
type Transport struct { Type int Write func(*Transport, string) ConsoleColorTheme *ConsoleColorTheme HTMLColorTheme *HTMLColorTheme Data []interface{} JSONFormatted bool }
A Transport struct