go-logger: github.com/mrz1836/go-logger Index | Examples | Files | Directories

package logger

import "github.com/mrz1836/go-logger"

Package logger is an easy to use, super fast and extendable logging package for Go

Index

Examples

Package Files

config.go log_entries.go logger.go parameters.go

Constants

const (
    LogEntriesPort = "10000"
    LogEntriesURL  = "data.logentries.com" // "us.data.logs.insight.rapid7.com"
    MaxRetryDelay  = 2 * time.Minute
    RetryDelay     = 100 * time.Millisecond
)

Package constants

func Data Uses

func Data(stackLevel int, logLevel LogLevel, message string, args ...KeyValue)

Data will format the log message to a standardized log entries compatible format. stackLevel 2 will tag the log with the location from where Data is called. This will print using the implementation's Println function

func Errorfmt Uses

func Errorfmt(stackLevel int, format string, v ...interface{})

Errorfmt is equivalent to Printf with a custom stack level, see Errorln for details

func Errorln Uses

func Errorln(stackLevel int, v ...interface{})

Errorln is equivalent to Println() except the stack level can be set to generate the correct log tag. A stack level of 2 is will tag the log with the location from where Errorln is called, and is equivalent to Println. Larger numbers step further back in the stack

func Fatalf Uses

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1)

func Fatalln Uses

func Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1)

func FileTag Uses

func FileTag(level int) string

FileTag tag file

ExampleFileTag example using FileTag()

Code:

// fileTag := FileTag(1)
fileTag := "go-logger/logger_test.go:go-logger.ExampleFileTag:102"
fmt.Println(fileTag)

Output:

go-logger/logger_test.go:go-logger.ExampleFileTag:102

func FileTagComponents Uses

func FileTagComponents(level int) []string

FileTagComponents file tag components

ExampleFileTagComponents example using FileTagComponents()

Code:

fileTag := FileTagComponents(1)
fmt.Println(fileTag[0])

Output:

go-logger/logger_test.go

func NoFileData Uses

func NoFileData(logLevel LogLevel, message string, args ...KeyValue)

NoFileData will format the log message to a standardized log entries compatible format. This will print using the implementation's Println function

func NoFilePrintf Uses

func NoFilePrintf(format string, v ...interface{})

NoFilePrintf calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Printf.

func NoFilePrintln Uses

func NoFilePrintln(v ...interface{})

NoFilePrintln calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Println.

func Printf Uses

func Printf(format string, v ...interface{})

Printf calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Printf.

func Println Uses

func Println(v ...interface{})

Println calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Println.

func SetImplementation Uses

func SetImplementation(impl Logger)

SetImplementation allows the log implementation to be swapped at runtime

type KeyValue Uses

type KeyValue interface {
    Key() string
    Value() interface{}
}

KeyValue key value for errors

type LogClient Uses

type LogClient struct {
    // contains filtered or unexported fields
}

LogClient configuration

func NewLogEntriesClient Uses

func NewLogEntriesClient(token, endpoint, port string) (*LogClient, error)

NewLogEntriesClient new client

func (*LogClient) Connect Uses

func (l *LogClient) Connect() error

Connect will connect to Log Entries

func (*LogClient) Fatalf Uses

func (l *LogClient) Fatalf(format string, v ...interface{})

Fatalf overloads built-in method

func (*LogClient) Fatalln Uses

func (l *LogClient) Fatalln(v ...interface{})

Fatalln overloads built-in method

func (*LogClient) Printf Uses

func (l *LogClient) Printf(format string, v ...interface{})

Printf overloads built-in method

func (*LogClient) Println Uses

func (l *LogClient) Println(v ...interface{})

Println overloads built-in method

func (*LogClient) ProcessQueue Uses

func (l *LogClient) ProcessQueue()

ProcessQueue process the queue

type LogLevel Uses

type LogLevel uint8

LogLevel our log level

const (
    DEBUG LogLevel = iota
    INFO
    WARN
    ERROR
)

Global constants

func (LogLevel) String Uses

func (l LogLevel) String() string

String turn log level to string

ExampleLogLevel_String example using level.String()

Code:

var level LogLevel
fmt.Println(level.String())

Output:

debug

type Logger Uses

type Logger interface {
    Println(v ...interface{})
    Printf(format string, v ...interface{})
    Fatalln(v ...interface{})
    Fatalf(format string, v ...interface{})
}

Logger interface describes the functionality that a log service must implement

type Parameter Uses

type Parameter struct {
    K   string      `json:"key"`
    V   interface{} `json:"value"`
}

Parameter is a standardized parameter struct for logger.Data()

func MakeParameter Uses

func MakeParameter(key string, value interface{}) *Parameter

MakeParameter creates a new Parameter (key/value)

func (*Parameter) Key Uses

func (p *Parameter) Key() string

Key implements the Logger KeyValue interface

func (*Parameter) String Uses

func (p *Parameter) String() string

Parameter json encodes the parameter into standard key=>value JSON

func (*Parameter) Value Uses

func (p *Parameter) Value() interface{}

Value implements the Logger KeyValue interface

Directories

PathSynopsis
examplesPackage main is an example package to show the use case of go-logger

Package logger imports 10 packages (graph) and is imported by 3 packages. Updated 2020-06-01. Refresh now. Tools for package owners.