logs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 25 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 rotation 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) MarshalText added in v0.3.0

func (f FileMode) MarshalText() ([]byte, error)

MarshalText satisfies an encoder.TextMarshaler interface.

func (FileMode) Mode added in v0.1.14

func (f FileMode) Mode() os.FileMode

Mode returns the compatible 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:"logFile" toml:"log_file" xml:"log_file" yaml:"logFile"`
	DebugLog  string   `json:"debugLog" toml:"debug_log" xml:"debug_log" yaml:"debugLog"`
	HTTPLog   string   `json:"httpLog" toml:"http_log" xml:"http_log" yaml:"httpLog"`
	LogFiles  int      `json:"logFiles" toml:"log_files" xml:"log_files" yaml:"logFiles"`
	LogFileMb int      `json:"logFileMb" toml:"log_file_mb" xml:"log_file_mb" yaml:"logFileMb"`
	FileMode  FileMode `json:"fileMode" toml:"file_mode" xml:"file_mode" yaml:"fileMode"`
	Debug     bool     `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
	Quiet     bool     `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
	NoUploads bool     `json:"noUploads" toml:"no_uploads" xml:"no_uploads" yaml:"noUploads"`
}

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

func (*LogConfig) GetActiveLogFilePaths added in v0.6.0

func (l *LogConfig) GetActiveLogFilePaths() []string

GetActiveLogFilePaths returns the configured log file paths.

type LogFileInfo added in v0.3.0

type LogFileInfo struct {
	ID   string
	Name string
	Path string
	Size int64
	Time time.Time
	Mode fs.FileMode
	Used bool
	User string
}

LogFileInfo is returned by GetAllLogFilePaths.

type LogFileInfos added in v0.3.0

type LogFileInfos struct {
	Dirs []string
	Size int64
	List []*LogFileInfo
}

LogFileInfos holds metadata about files.

func GetFilePaths added in v0.3.0

func GetFilePaths(files ...string) *LogFileInfos

GetFilePaths is a helper function that returns data about similar files in a folder with the provided file(s). This is useful to find "all the log files" or "all the .conf files" in a folder. Simply pass in 1 or more file paths, and any files in the same folder with the same extension will be returned.

func (*LogFileInfos) Len added in v0.3.0

func (l *LogFileInfos) Len() int

func (*LogFileInfos) Less added in v0.3.0

func (l *LogFileInfos) Less(i, j int) bool

func (*LogFileInfos) Swap added in v0.3.0

func (l *LogFileInfos) Swap(i, j int)

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

	LogConfig *LogConfig
	// 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 deferred 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) DebugEnabled added in v0.3.2

func (l *Logger) DebugEnabled() bool

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) ErrorfNoShare added in v0.3.2

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

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

func (*Logger) GetAllLogFilePaths added in v0.3.0

func (l *Logger) GetAllLogFilePaths() *LogFileInfos

GetAllLogFilePaths searches the disk for log file names.

func (*Logger) GetDebugLog added in v0.3.2

func (l *Logger) GetDebugLog() *log.Logger

func (*Logger) GetErrorLog added in v0.3.2

func (l *Logger) GetErrorLog() *log.Logger

func (*Logger) GetInfoLog added in v0.3.2

func (l *Logger) GetInfoLog() *log.Logger

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.

Directories

Path Synopsis
Package share is here so we can keep website cruft out of the logs package.
Package share is here so we can keep website cruft out of the logs package.

Jump to

Keyboard shortcuts

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