nglog

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 2 Imported by: 0

README

nglog

GOAL

  • to be a Log4j equivalent for Go

Logging

  • If the log is just a record of something happening, if it could be aggregated, it's probably a metric (Prometheus).

  • If the log is something important, then it's not a log it's an alert. Send it by email, pagerduty, chat-ops, etc.

  • If the log is not something important then remove it.

Setup Logging for project (Basic)
ca := log.NewConsoleAppender("*")
log.Modify(log.LogLevel(log.INFO), log.ColorsOn(), log.Appenders(ca, fa))
Setup Logging with file output
logfile = filepath.Join(file.HomeFolder(), appName+".log")
fa, err := log.NewFileAppender("*", logfile, "", 0)
if err != nil {
    log.Logf(log.FATAL, "issue creating file appender\n%+v", err)
}
ca := log.NewConsoleAppender("*")
log.Modify(log.LogLevel(log.INFO), log.ColorsOn(), log.Appenders(ca, fa))
Setup Logging with JSON output
logfile = filepath.Join(file.HomeFolder(), appName+".log")
fa, err := log.NewFileAppender("*", logfile, "", 0)
if err != nil {
    log.Logf(log.FATAL, "issue creating file appender\n%+v", err)
}
ca := log.NewConsoleAppender("*")
log.Modify(log.LogLevel(log.DEBUG), log.Formatr(new(log.JSONLayout)), log.Appenders(ca,fa))
Setup Logging with Failover
logfile = filepath.Join(file.HomeFolder(), appName+".log")
fa, err := log.NewFileAppender("*", logfile, "", 0)
if err != nil {
    log.Logf(log.FATAL, "issue creating file appender\n%+v", err)
}
ca := log.NewConsoleAppender("*")
fa := log.NewFailoverAppender(fileAp, []log.Appender{ca})
log.Modify(log.LogLevel(log.DEBUG), log.Formatr(new(log.JSONLayout)), log.Appenders(fa))
Setup Logging with Failover and Filtering
logfile = filepath.Join(file.HomeFolder(), appName+".log")
fa, err := log.NewFileAppender("github.com/colt3k/nglog/", logfile, "", 0)
if err != nil {
    log.Logf(log.FATAL, "issue creating file appender\n%+v", err)
}
ca := log.NewConsoleAppender("*")
fa := log.NewFailoverAppender(fileAp, []log.Appender{ca})
log.Modify(log.LogLevel(log.DEBUG), log.Formatr(new(log.JSONLayout)), log.Appenders(fa))
Setup Logging with Mailer
ma, err := log.NewMailAppender("*", "my.mailserver.com", "youruser", "yourpass", "from@somewhere.com", "user@to.com", "Test message", 25)
if err != nil {
    log.Logf(log.FATAL, "issue creating mail appender\n%+v", err)
}
ca := log.NewConsoleAppender("*")
tl := new(log.TextLayout)
tl.DisableColors = true
log.Modify(log.LogLevel(log.DEBUG), log.Formatr(tl), log.Appenders(ca, ma))        
Setup Logging with HTTP Appender using JSON
ha, err := log.NewHTTPAppender("*", "http://localhost:8080", "", "")
if err != nil {
    log.Logf(log.FATAL, "issue creating http appender\n%+v", err)
}
ca := log.NewConsoleAppender("*")
log.Modify(log.LogLevel(log.DEBUG), log.Formatr(new(log.JSONLayout)), log.Appenders(ca, ha))
Appenders
- Console
- Failover
- File
- Mail
- HTTP
- TCP socket
- syslog
Layouts
Text
JSON    

Coming

Appenders

- storage (db, file, nosql(mongodb, couchdb))
- MQ Apps (ZeroMQ, JeroMQ, RabbitMQ)
- Rewrite
- JPA, JMS, Cassandra, Async

Influencers

originally influenced by logrus, log4j and other great loggers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook interface {
}

type Logger

type Logger interface {
	Flags() int
	Level() enum.LogLevel
	Logln(lvl enum.LogLevel, args ...interface{})
	Logf(lvl enum.LogLevel, format string, args ...interface{})
	Print(args ...interface{})
	Printf(format string, args ...interface{})
	Println(args ...interface{})
	SetLevel(level enum.LogLevel)
	SetFlags(flg enum.Flags)
	SetFormatter(formatter ng.Layout)
	WithFields(fields []ng.Fields) *ng.LogMsg
}

Directories

Path Synopsis
ers
internal
pkg/enum
Code generated by go generate This file was generated by robots at 2018-05-21 16:26:14.487123326 +0000 UTC Code generated by go generate This file was generated by robots at 2018-05-21 16:26:06.261281984 +0000 UTC
Code generated by go generate This file was generated by robots at 2018-05-21 16:26:14.487123326 +0000 UTC Code generated by go generate This file was generated by robots at 2018-05-21 16:26:06.261281984 +0000 UTC
//http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors //Global Format \u001b[+COLOR+m Non BRIGHT \u001b[+COLOR+;1m BRIGHT // FORMATTING \u001b[1m BOLD \u001b[4m Underline \u001b[7m Reversed // Formats Foreground 8 bit \u001b[30m 16 bit \u001b[30;1m 256 bit \u001b[38;5;${ID}m //Colors CLR_BLK = "\x1b[30m" // black CLR_BLKBRIGHT = "\x1b[30;1m" // black bright CLR_RED = "\x1b[31m" // red CLR_REDBRT = "\x1b[31;1m" // red CLR_GRN = "\x1b[32m" // green CLR_YLLW = "\x1b[33m" // yellow CLR_BLU = "\x1b[34;1m" // blue CLR_MAG = "\x1b[35;1m" // magenta CLR_CYAN = "\x1b[36;1m" // cyan CLR_WHT = "\x1b[37;1m" // white CLR_RESET = "\x1b[0m" // reset to default //ASCII 256 CLR_DEFAULT = "\x1b[38;5;10m" CLR_ERR = "\x1b[38;5;196m" //red CLR_WARN = "\x1b[38;5;11m" //yellow CLR_INFO = "\x1b[38;5;174m" // light red/brown //Formats Background Color bright versions of the background colors do not change the background, but rather make the foreground text brighter 8 bit \u001b[40m 16 bit \u001b[40;1m 256 bit \u001b[48;5; CLRBG_BLK = "\x1b[40m" CLRBG_BLKBRIGHTb = "\x1b[40;1m"
//http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors //Global Format \u001b[+COLOR+m Non BRIGHT \u001b[+COLOR+;1m BRIGHT // FORMATTING \u001b[1m BOLD \u001b[4m Underline \u001b[7m Reversed // Formats Foreground 8 bit \u001b[30m 16 bit \u001b[30;1m 256 bit \u001b[38;5;${ID}m //Colors CLR_BLK = "\x1b[30m" // black CLR_BLKBRIGHT = "\x1b[30;1m" // black bright CLR_RED = "\x1b[31m" // red CLR_REDBRT = "\x1b[31;1m" // red CLR_GRN = "\x1b[32m" // green CLR_YLLW = "\x1b[33m" // yellow CLR_BLU = "\x1b[34;1m" // blue CLR_MAG = "\x1b[35;1m" // magenta CLR_CYAN = "\x1b[36;1m" // cyan CLR_WHT = "\x1b[37;1m" // white CLR_RESET = "\x1b[0m" // reset to default //ASCII 256 CLR_DEFAULT = "\x1b[38;5;10m" CLR_ERR = "\x1b[38;5;196m" //red CLR_WARN = "\x1b[38;5;11m" //yellow CLR_INFO = "\x1b[38;5;174m" // light red/brown //Formats Background Color bright versions of the background colors do not change the background, but rather make the foreground text brighter 8 bit \u001b[40m 16 bit \u001b[40;1m 256 bit \u001b[48;5; CLRBG_BLK = "\x1b[40m" CLRBG_BLKBRIGHTb = "\x1b[40;1m"
test
tcp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL