golog: github.com/ivpusic/golog Index | Files | Directories

package golog

import "github.com/ivpusic/golog"


Package Files

appender.go golog.go logger.go


var (
    DEBUG = Level{
        Value: 10,
        color: "blue",
        icon:  "★",
        Name:  "DEBUG",

    INFO = Level{
        Value: 20,
        color: "green",
        icon:  "♥",
        Name:  "INFO",

    WARN = Level{
        Value: 30,
        color: "yellow",
        icon:  "\u26A0",
        Name:  "WARN",

    ERROR = Level{
        Value: 40,
        color: "red",
        Name:  "ERROR",
        icon:  "✖",

    PANIC = Level{
        Value: 50,
        color: "black",
        icon:  "☹",
        Name:  "PANIC",

func Disable Uses

func Disable(name string)

Will disable all logs comming from logger with provided name

func Enable Uses

func Enable(name string)

Will enable all logs comming to logger with provided name

type Appender Uses

type Appender interface {
    // method for injecting log to some source
    // when appender receives Log instance through this method,
    // it should decide what to do with log
    Append(log Log)

    // method will return appender ID
    // it will be used for disabling appenders
    Id() string

Interface for implementing custom appenders.

type Conf Uses

type Conf map[string]string

Convinient type for representing appender configuration

type Ctx Uses

type Ctx map[string]interface{}

type Level Uses

type Level struct {
    // level priority value
    // bigger number has bigger priority
    Value int `json:"value"`

    // level name
    Name string `json:"name"`
    // contains filtered or unexported fields

Representing log level

type Log Uses

type Log struct {
    // date and time of log
    Time time.Time `json:"time"`

    // logged message
    Message string `json:"message"`

    // log level
    Level Level `json:"level"`

    // additional data sent to log
    // this part should be handled by appenders
    // appender can decide to ignore data or to store it on specific way
    Data []interface{} `json:"data"`

    // represents data bound to contextual logger
    Ctx Ctx `json:"ctx"`

    // id of process which made log
    Pid int `json:"pid"`

    // logger instance
    Logger *Logger `json:"logger"`

Representing one Log instance

type Logger Uses

type Logger struct {

    // name of logger
    // logger name will be shown in stdout appender output
    // also it can be used to enable/disable logger
    Name string `json:"name"`

    // minimum level of log to be shown
    Level Level `json:"-"`

    // if this flag is set to true, in case any errors in appender
    // appender should panic. This also depends on appender implementation,
    // so appender can decide to ignore or to accept information in this flag
    DoPanic bool `json:"-"`
    // contains filtered or unexported fields

Representing one logger instance Logger can have multiple appenders, it can enable it, or disable it. Also you can define level which will be specific to this logger.

var (
    // instance of default logger
    Default *Logger

func GetLogger Uses

func GetLogger(name string) *Logger

Function for getting logger instance. Method returns singleton logger instance.

func (*Logger) AddContextKey Uses

func (l *Logger) AddContextKey(key string, value interface{}) *Logger

func (*Logger) Copy Uses

func (l *Logger) Copy() *Logger

Will copy current logger and return instance of new one.

func (*Logger) Debug Uses

func (l *Logger) Debug(msg interface{}, data ...interface{})

Making log with DEBUG level.

func (*Logger) Debugf Uses

func (l *Logger) Debugf(msg string, params ...interface{})

Making formatted log with DEBUG level.

func (*Logger) Disable Uses

func (l *Logger) Disable(target interface{})

If you want to disable logs from some appender you can use this method. You have to call method either with appender instance, or you can pass appender Id as argument. If appender is found, it will be removed from list of appenders of this logger, and all other further logs won't be received by this appender.

func (*Logger) Enable Uses

func (l *Logger) Enable(appender Appender)

When you want to send logs to another appender, you should create instance of appender and call this method. Method is expecting appender instance to be passed to this method. At the end passed appender will receive logs

func (*Logger) Error Uses

func (l *Logger) Error(msg interface{}, data ...interface{})

Making log with ERROR level.

func (*Logger) Errorf Uses

func (l *Logger) Errorf(msg string, params ...interface{})

Making formatted log with ERROR level.

func (*Logger) Info Uses

func (l *Logger) Info(msg interface{}, data ...interface{})

Making log with INFO level.

func (*Logger) Infof Uses

func (l *Logger) Infof(msg string, params ...interface{})

Making formatted log with INFO level.

func (*Logger) Panic Uses

func (l *Logger) Panic(msg interface{}, data ...interface{})

Making log with PANIC level.

func (*Logger) Panicf Uses

func (l *Logger) Panicf(msg string, params ...interface{})

Making formatted log with PANIC level.

func (*Logger) SetContext Uses

func (l *Logger) SetContext(ctx Ctx) *Logger

Will set context to current logger. Later appenders will be able to extract context from Log instance.

func (*Logger) Warn Uses

func (l *Logger) Warn(msg interface{}, data ...interface{})

Making log with WARN level.

func (*Logger) Warnf Uses

func (l *Logger) Warnf(msg string, params ...interface{})

Making formatted log with WARN level.

type Stdout Uses

type Stdout struct {
    DateFormat string

Representing stdout appender.

func StdoutAppender Uses

func StdoutAppender() *Stdout

Function for creating and returning new stdout appender instance.

func (*Stdout) Append Uses

func (s *Stdout) Append(log Log)

Appending logs to stdout.

func (*Stdout) Id Uses

func (s *Stdout) Id() string

Getting Id of stdout appender Id of default stdout appender is "github.com/ivpusic/golog/stdout"



Package golog imports 5 packages (graph) and is imported by 15 packages. Updated 2017-06-08. Refresh now. Tools for package owners.