Documentation ¶
Index ¶
- func Chan(entryChan chan<- logger.Entry) logger.HandlerInterface
- func Gelf(network string, address string) logger.HandlerInterface
- func GelfFromConnection(connection net.Conn) logger.HandlerInterface
- func GelfTCP(network string, address string) logger.HandlerInterface
- func GelfTCPFromConnection(connection *net.TCPConn) logger.HandlerInterface
- func GelfUDP(network string, address string) logger.HandlerInterface
- func GelfUDPFromConnection(connection *net.UDPConn) logger.HandlerInterface
- func Group(handlers ...logger.HandlerInterface) logger.HandlerInterface
- func LogRotateFileStream(fileNameFormat string, format string, timeFormat string, ...) (logger.HandlerInterface, error)
- func Socket(connection net.Conn, formatter logger.FormatterInterface) logger.HandlerInterface
- func Stream(writer io.Writer, formatter logger.FormatterInterface) logger.HandlerInterface
- func Syslog(formatter logger.FormatterInterface, network, raddr string, ...) (logger.HandlerInterface, error)
- func TimeRotateFileStream(fileNameFormat string, timeFormat string, formatter logger.FormatterInterface, ...) (logger.HandlerInterface, error)
- func TimeRotateFromProvider(provider writer.Provider, formatter logger.FormatterInterface, ...) (logger.HandlerInterface, error)
- type Memory
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chan ¶
func Chan(entryChan chan<- logger.Entry) logger.HandlerInterface
Chan will send Entry into a given go channel
func Gelf ¶
func Gelf(network string, address string) logger.HandlerInterface
Gelf will send Entry into gelf writer(depending on network, address)
func GelfFromConnection ¶
func GelfFromConnection(connection net.Conn) logger.HandlerInterface
GelfFromConnection will send Entry into gelf writer(depending on GelfFromConnection)
func GelfTCP ¶
func GelfTCP(network string, address string) logger.HandlerInterface
GelfTCP will send Entry into TCP gelf writer(depending on network, address)
use GelfTCPFromConnection func if you want to handle the connection error and Closure
func GelfTCPFromConnection ¶
func GelfTCPFromConnection(connection *net.TCPConn) logger.HandlerInterface
GelfTCPFromConnection will return GelfTCP socket with the current TCPConn
func GelfUDP ¶
func GelfUDP(network string, address string) logger.HandlerInterface
GelfUDP will send Entry into UDP gelf writer(depending on network, address)
use GelfUDPFromConnection func if you want to handle the connection error and Closure
CAUTION: Logstash only supports Gzip compression https://github.com/elastic/logstash/issues/2387
func GelfUDPFromConnection ¶
func GelfUDPFromConnection(connection *net.UDPConn) logger.HandlerInterface
GelfUDPFromConnection will return GelfUDP socket with the current TCPConn
func Group ¶
func Group(handlers ...logger.HandlerInterface) logger.HandlerInterface
Group will send Entry to each underlying handlers useful when you want to send your log in multiple destination eg stdOut/file/logserver
Example ¶
package main import ( "os" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger" "github.com/gol4ng/logger/handler" ) func main() { lineFormatter := formatter.NewDefaultFormatter() lineLogHandler := handler.Stream(os.Stdout, lineFormatter) jsonFormatter := formatter.NewJSONEncoder() jsonLogHandler := handler.Stream(os.Stdout, jsonFormatter) groupHandler := handler.Group(lineLogHandler, jsonLogHandler) _ = groupHandler(logger.Entry{Message: "Log example"}) }
Output: <emergency> Log example {"Message":"Log example","Level":0,"Context":null}
func LogRotateFileStream ¶
func LogRotateFileStream(fileNameFormat string, format string, timeFormat string, formatter logger.FormatterInterface, interval time.Duration) (logger.HandlerInterface, error)
LogRotateFileStream will create a TimeRotateFileStream that create file rotator with a given format name and rotation interval this handler will create one static file with the given name and backup file when rotate occurs over the time (with the given interval)
func Socket ¶
func Socket(connection net.Conn, formatter logger.FormatterInterface) logger.HandlerInterface
Socket will create a an handler that format and send data into a connection
func Stream ¶
func Stream(writer io.Writer, formatter logger.FormatterInterface) logger.HandlerInterface
Stream will format and write Entry into io.writer
Example ¶
package main import ( "os" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { lineFormatter := formatter.NewDefaultFormatter() lineLogHandler := handler.Stream(os.Stdout, lineFormatter) _ = lineLogHandler(logger.Entry{Message: "Log example"}) }
Output: <emergency> Log example
func Syslog ¶
func Syslog(formatter logger.FormatterInterface, network, raddr string, priority syslog.Priority, tag string) (logger.HandlerInterface, error)
Syslog will format and send Entry to a syslog server
Example ¶
You can run the command below to show syslog messages syslog -F '$Time $Host $(Sender)[$(PID)] <$((Level)(str))>: $Message' Jan 22 22:42:14 hades my_go_logger[113] <Notice>: notice Log example2 &map[ctx_key:ctx_value] Jan 22 22:42:14 hades my_go_logger[113] <Warning>: warning Log example3 &map[ctx_key:ctx_value] Jan 22 22:42:14 hades my_go_logger[113] <Error>: error Log example4 &map[ctx_key:ctx_value] Jan 22 22:42:14 hades my_go_logger[113] <Critical>: critical Log example5 &map[ctx_key:ctx_value] Jan 22 22:42:14 hades my_go_logger[113] <Alert>: alert Log example6 &map[ctx_key:ctx_value] Jan 22 22:42:14 hades my_go_logger[113] <Emergency>: emergency Log example7 &map[ctx_key:ctx_value]
package main import ( "log/syslog" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { syslogHandler, _ := handler.Syslog( formatter.NewLine("%[2]s %[1]s %[3]s"), "", "", syslog.LOG_DEBUG, "my_go_logger") _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.DebugLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.InfoLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.NoticeLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.WarningLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.ErrorLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.CriticalLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.AlertLevel}) _ = syslogHandler(logger.Entry{Message: "Log example", Level: logger.EmergencyLevel}) }
Output:
func TimeRotateFileStream ¶
func TimeRotateFileStream(fileNameFormat string, timeFormat string, formatter logger.FormatterInterface, interval time.Duration) (logger.HandlerInterface, error)
TimeRotateFileStream handler will create a TimeRotateWriter that creates a file rotator with a given logFileName format and a rotation interval it will create a new file each time rotate occurs
func TimeRotateFromProvider ¶
func TimeRotateFromProvider(provider writer.Provider, formatter logger.FormatterInterface, interval time.Duration) (logger.HandlerInterface, error)
TimeRotateFromProvider will create a TimeRotateFromProvider that create io.Writer rotator with a given rotation interval
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory will store Entry to slice entries mainly develop for testing purpose in order to do some entries assertion
func (*Memory) CleanEntries ¶
func (s *Memory) CleanEntries()
CleanEntries will reset the in memory entries list
func (*Memory) GetAndCleanEntries ¶
GetAndCleanEntries will return and clean the in memory entries list
func (*Memory) GetEntries ¶
GetEntries will return the in memory entries list