logs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 15 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 FileMode added in v0.1.14

type FileMode os.FileMode

FileMode is used to unmarshal a unix file mode from the config file.

func (FileMode) Mode added in v0.1.14

func (f FileMode) Mode() os.FileMode

Mode returns the compatable os.FileMode.

func (FileMode) String added in v0.1.14

func (f FileMode) String() string

String creates a unix-octal version of a file mode.

func (*FileMode) UnmarshalText added in v0.1.14

func (f *FileMode) UnmarshalText(text []byte) error

UnmarshalText turns a unix file mode, wrapped in quotes or not, into a usable os.FileMode.

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"`
	FileMode  FileMode `json:"file_mode" toml:"file_mode" xml:"file_mode" yaml:"file_mode"`
	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) CapturePanic added in v0.1.15

func (l *Logger) CapturePanic()

CapturePanic can be defered in any go routine to log any panic that occurs.

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.

Jump to

Keyboard shortcuts

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