# README
log-go
Log-go is a logging library developed with simplicity and thread-safety in mind. It doesn't support any extra-fancy features. Just like Go itself.
If you wish to improve upon this, you are welcome to send me a Pull Request.
Features
- Different log levels like Fatal, Error, Info, etc.
- Configurable buffered writer (
os.Stdout
,*File
, etc.) - Thread safety
- Prefixes to separate logs from everything else
- Extremely simple setup
- Coloured terminal output
- Well-tested
Log Levels
This library comes with the following log levels:
- Panic
- Fatal
- Error
- Warn
- Info
- Debug
These are enumerated as LevelDebug
, LevelInfo
, etc., so that you won't have
to memorise them by numbers.
Each Log
instance has five methods that are named precisely after the levels.
Use them like so:
logger := log.Default()
logger.Warn("this is a warning")
Basic Setup
package main
import (
"os"
"github.com/sharpvik/log-go"
)
func init() {
// Change log level.
log.SetLevel(log.LevelInfo) // default: LevelError
// Change log writer.
file, _ := os.Create("server.log")
log.SetWriter(file) // default: os.Stdout
}
func main() {
// Computations ...
x := 40 + 2
// Print log with priority level Info.
log.Infof("x = %d", x)
// * 11/01/2021 23:07:08 INFO x = 42
}
Examples
You are welcome to look at some examples too!
# Packages
No description provided by the author
# Functions
Debug writes formatted debug message to l.writer.
Debugf writes formatted message to l.writer.
Default returns a default logger instance used withing this package and available globally.
Error writes formatted error to l.writer.
Errorf writes formatted error to l.writer.
Fatal is equivalent to Error and os.Exit(1).
Fatalf is equivalent to Error and os.Exit(1).
Info writes formatted info message to l.writer.
Infof writes formatted message to l.writer.
New returns a new custom logger instance.
Panic is equivalent to panic(formattedMessage).
Panicf is equivalent to panic(formattedMessage).
SetLevel changes std's priority level.
SetWriter changes std's writer.
Warn writes formatted warning to l.writer.
Warnf writes formatted warning to l.writer.
# Constants
Log Priority levels are listed here as constants for convenience.
Log Priority levels are listed here as constants for convenience.
Log Priority levels are listed here as constants for convenience.
Log Priority levels are listed here as constants for convenience.
Log Priority levels are listed here as constants for convenience.
Log Priority levels are listed here as constants for convenience.
# Type aliases
Priority is a type alias for logging priority levels.