logs

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package logs provides the low-level routines for directing log messages. It creates several logging channels for debug, info, errors, http, etc. These channels are directed to log files and/or stdout depending on how the application is configured. This package reads its configuration directly from a config file. In here you will find the log roatation config for rotatorr, panic redirection, and external logging methods.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCloseCustom = fmt.Errorf("cannot close custom logs directly")
)

Custom errors.

Functions

This section is empty.

Types

type Cooler

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

Cooler allows you to save/get if something is already running or not (active).

func (*Cooler) Active

func (c *Cooler) Active() bool

Active returns true if a cooler already active. Returns false if not, and activates the cooler.

func (*Cooler) Done

func (c *Cooler) Done()

Done resets a cooler.

type LogConfig added in v0.1.6

type LogConfig struct {
	AppName   string `json:"-"`
	LogFile   string `json:"log_file" toml:"log_file" xml:"log_file" yaml:"log_file"`
	DebugLog  string `json:"debug_log" toml:"debug_log" xml:"debug_log" yaml:"debug_log"`
	HTTPLog   string `json:"http_log" toml:"http_log" xml:"http_log" yaml:"http_log"`
	LogFiles  int    `json:"log_files" toml:"log_files" xml:"log_files" yaml:"log_files"`
	LogFileMb int    `json:"log_file_mb" toml:"log_file_mb" xml:"log_file_mb" yaml:"log_file_mb"`
	Debug     bool   `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
	Quiet     bool   `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
}

LogConfig allows sending logs to rotating files. Setting an AppName will force log creation even if LogFile and HTTPLog are empty.

type Logger

type Logger struct {
	ErrorLog *log.Logger // Shares a Writer with InfoLog.
	DebugLog *log.Logger // Shares a Writer with InfoLog by default. Changeable.
	InfoLog  *log.Logger
	HTTPLog  *log.Logger
	// contains filtered or unexported fields
}

Logger provides some methods with baked in assumptions.

func CustomLog added in v0.1.6

func CustomLog(filePath, logName string) *Logger

CustomLog allows the creation of ad-hoc rotating log files from other packages. This is not thread safe with Rotate(), so do not call them at the same time.

func New

func New() *Logger

New returns a new Logger with debug off and sends everything to stdout.

func (*Logger) Close added in v0.1.6

func (l *Logger) Close() (errors []error)

Close closes all open log files. Does not work on custom logs.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug writes log lines... to stdout and/or a file.

func (*Logger) Debugf

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

Debugf writes log lines... to stdout and/or a file.

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error writes log lines... to stdout and/or a file.

func (*Logger) Errorf

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

Errorf writes log lines... to stdout and/or a file.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print writes log lines... to stdout and/or a file.

func (*Logger) Printf

func (l *Logger) Printf(msg string, v ...interface{})

Printf writes log lines... to stdout and/or a file.

func (*Logger) Rotate

func (l *Logger) Rotate() (errors []error)

Rotate rotates the log files. If called on a custom log, only rotates that log file.

func (*Logger) SetupLogging

func (l *Logger) SetupLogging(config *LogConfig)

SetupLogging splits log writers into a file and/or stdout.

type Timer

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

Timer is used to set a cooldown time.

func (*Timer) Active

func (t *Timer) Active(d time.Duration) bool

Active returns true if a timer is active, otherwise it becomes active.

Jump to

Keyboard shortcuts

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