logger

package module
v3.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 10 Imported by: 0

README

Logger: custom logger package for Go.

Logger package help you easier write log to io.Writer. All methods fully support standard log package, but have extra features.

Install

For install logger, just run go get -u github.com/neliseev/logger or glide get github.com/neliseev/logger

Usage

Simple in main file you should initialise logger.

package main

import "github.com/neliseev/logger"

var log *logger.Log // Using log subsystem

func init() {
	// Initialization log system
	var err error

	if log, err = logger.NewFileLogger("/var/log/example/main.log", 8); err != nil {
		panic(err)
	}
}

func main() {
    log.Info("Starting main packge")
...
}

Logger automatically create all subfolder by defined path.

For re-use current initialised logger, just define var log *logger.Log, example:

package example

import "github.com/neliseev/logger"

var log *logger.Log // Using log subsystem

func Some() {
    log.Debug("Hello, Wold!")
}
License

Copyright (C) 2017 Nikita Eliseev

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	EMERGENCY int = iota // 0
	ALERT                // 1
	CRITICAL             // 2
	ERROR                // 3
	WARNING              // 4
	NOTICE               // 5
	INFO                 // 6
	DEBUG                // 7
)

log level constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Configurer

type Configurer interface {
	LogFile() string
	LogLevel() int

	LokiPushURL() string
	LokiLabels() string // "{foo=\"bar\"}"
	LokiBatchWait() time.Duration
	LokiSendLevel() int
}

Configurer represents config object interface

type Log

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

Log struct represents application logger

func (*Log) Alert

func (log *Log) Alert(a ...interface{})

Alert wraps println

func (*Log) Alertf

func (log *Log) Alertf(format string, a ...interface{})

Alertf wraps formatted Error

func (*Log) Close added in v1.1.0

func (log *Log) Close()

Close the log file if used

func (*Log) Critical added in v1.1.0

func (log *Log) Critical(a ...interface{})

Critical wraps println

func (*Log) Criticalf

func (log *Log) Criticalf(format string, a ...interface{})

Criticalf wraps formatted Error

func (*Log) Debug

func (log *Log) Debug(a ...interface{})

Debug wraps println

func (*Log) Debugf

func (log *Log) Debugf(format string, a ...interface{})

Debugf wraps formatted Notice

func (*Log) Emergency added in v1.1.0

func (log *Log) Emergency(a ...interface{})

Emergency wraps println

func (*Log) Emergencyf

func (log *Log) Emergencyf(format string, a ...interface{})

Emergencyf wraps formatted Error

func (*Log) Error added in v1.1.0

func (log *Log) Error(a ...interface{})

Error wraps println

func (*Log) Errorf

func (log *Log) Errorf(format string, a ...interface{})

Errorf wraps formatted Error

func (*Log) Info

func (log *Log) Info(a ...interface{})

Info wraps println

func (*Log) Infof

func (log *Log) Infof(format string, a ...interface{})

Infof wraps formatted Notice

func (*Log) Notice

func (log *Log) Notice(a ...interface{})

Notice wraps println

func (*Log) Noticef

func (log *Log) Noticef(format string, a ...interface{})

Noticef wraps formatted Notice

func (*Log) Warning added in v1.1.0

func (log *Log) Warning(a ...interface{})

Warning wraps println

func (*Log) Warningf

func (log *Log) Warningf(format string, a ...interface{})

Warningf wraps formatted Warning

type Logger

type Logger interface {
	Emergency(a ...interface{})
	Emergencyf(format string, a ...interface{})
	Alert(a ...interface{})
	Alertf(format string, a ...interface{})
	Critical(a ...interface{})
	Criticalf(format string, a ...interface{})
	Error(a ...interface{})
	Errorf(format string, a ...interface{})
	Warning(a ...interface{})
	Warningf(format string, a ...interface{})
	Notice(a ...interface{})
	Noticef(format string, a ...interface{})
	Info(a ...interface{})
	Infof(format string, a ...interface{})
	Debug(a ...interface{})
	Debugf(format string, a ...interface{})
	Close()
}

func New added in v1.1.0

func New(cfg Configurer) (Logger, error)

New constructor for application logger

Fields:

path  - path to log file
level - log level, possible levels:
  0 - Emergency, with panic exit.
  1 - Alert, with exit 2.
  2 - Critical, with ext 1.
  3 - Errors.
  4 - Warnings.
  5 - Notice.
  6 - Info.
  7 - Debug.
func main() {
  // initialization application log system
  var err error
  logger := logger.Log{}
  if logger, err = logger.NewLogger("/some/path", 0); err != nil {
    panic(err)
  }
}

Jump to

Keyboard shortcuts

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