minori

package module
v0.0.0-...-e305eb4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 4 Imported by: 5

README

Minori

Minori is a very simple logger for Golang.

Why

The popular loggers were too big for my needs, i just needed basic console I/O with fancy output.

It uses ANSI colors for fancy output but it will work on Windows too, Thanks to go-colorable

It is used in my own projects as it is specifically made for my uses but it's documented and open-sourced if anyone else wants to use it as well.

Install

$ go get github.com/ravener/minori

Usage

package main

import (
  "github.com/ravener/minori"
)

var logger = minori.GetLogger("app")

func main() {
  logger.Info("Booting up...")
  err := bootUp()
  if err != nil {
    logger.Fatal(err)
  }
}

It has the basic levels of logging (in order of verbosity):

  • Debug
  • Info
  • Warn
  • Error
  • Panic
  • Fatal

There's also format versions available with f suffixes for a Printf-like usage, e.g Errorf

The log levels can be modified globally by minori.SetLevel(), there are level constants with same name as log methods but uppercased, e.g minori.SetLevel(minori.DEBUG) will print everything while minori.SetLevel(minori.ERROR) will only print Errors/Panics/Fatal errors. There is also an OFF constant to suppress logging entirely.

Each logger can also have it's own level (e.g you want to debug a specific component but don't want to get debug messages from others.) use minori.GetLoggerLevel("app", minori.DEBUG) the second argument works the same as SetLevel but for this logger only.

Logging to a file.

I did not need this part but since it was so easy to add support for it, i did it but it's very basic, it doesn't have any MaximumFileSize opions or similar, you are responsible for that.

You can use minori.GetLoggerOutput("app", writer) (or minori.GetLoggerLevelOutput("app", minori.DEBUG, writer) if you are using per-logger levels) where writer is any io.Writer to print the output to, by default it's a go-colorable stdout, when using this method it will be wrapped by go-colorable's non-colorable to strip off color output.

Example

See also a runnable example in the example directory

License

MIT License

Documentation

Overview

Minori is a minimal logging package for Golang.

Index

Constants

View Source
const (
	OFF   = 0
	FATAL = 1
	PANIC = 2
	ERROR = 3
	WARN  = 4
	INFO  = 5
	DEBUG = 6
)

Variables

View Source
var LogLevel = 6

Functions

func SetLevel

func SetLevel(level int)

SetLevel sets the global log level. Panics if level is invalid.

Types

type Logger

type Logger struct {
	Name  string
	Out   io.Writer
	Level int // -1 to use the global LogLevel
}

func GetLogger

func GetLogger(name string) *Logger

func GetLoggerLevel

func GetLoggerLevel(name string, level int) *Logger

func GetLoggerLevelOutput

func GetLoggerLevelOutput(name string, level int, writer io.Writer) *Logger

func GetLoggerOutput

func GetLoggerOutput(name string, writer io.Writer) *Logger

func (*Logger) Debug

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

func (*Logger) Debugf

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

func (*Logger) Error

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

func (*Logger) Errorf

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

func (*Logger) Fatal

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

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Info

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

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

func (*Logger) Panic

func (l *Logger) Panic(v interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

func (*Logger) Warn

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

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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