yal

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 5 Imported by: 5

README

Yet Another Logger

This is a tiny dependency free library for very simple logging for applications and scripts where logging is a small part of the process and not used for robust metric collection. This should, for example, not be used for a large web server or background process. It's specifically developed for easily adding a logger into a CLI application or script.

If you do end up using this, you should vendor, or copy it into your code base.

Features

  • Leveled Logger
  • Optional Colored logging

Example

2022-07-21 14:41:56: [INFO] This is a info message
2022-07-21 14:41:56: [DEBUG] This is a debug message
2022-07-21 14:41:56: [ERROR] This is a error message
2022-07-21 14:41:56: [FATAL] This is a fatal message

Usage

Singleton Logger

The library can be used as an easy drop in logger that acts as a singleton. There are top level methods for Info, Debug, Error, Warn, and Fatal logging that call the top level Log variable which is an instance of the Logger struct.

package main

import (
	"fmt"

	"github.com/hay-kot/yal"
)

func main() {
	yal.Log.Level = yal.LevelDebug // Set the global log level

	fmt.Println("\nGlobal Logger: Color")

	yal.Info("This is a info message")
	yal.Debug("This is a debug message")
	yal.Error("This is a error message")
	yal.Fatal("This is a fatal message")
}

Documentation

Overview

Yet Another Logger (yal) is a simple and lightweight colored and leveled logger. It's designed to be used as a singleton type logging solution that can be dropped into scripts and CLIs without complex dependency injection or configuration.

yal provides a top level singleton logger that is exposed to the user with the following levels Info, Debug, Warn, Error, Fatal.

Call methods

yal.Info("Hello World")

yal.Infof("Hello World %s", "World")

Set Properties on Logger

yal.Log.Colors = false

yal.Log.Level = yal.LevelWarn

Index

Constants

This section is empty.

Variables

View Source
var Level = LogLevel(0)
View Source
var Log = Default()

Functions

func Debug

func Debug(v ...interface{})

func Debugf

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

func Error

func Error(v ...interface{})

func Errorf

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

func Fatal

func Fatal(v ...interface{})

func Fatalf

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

func Info

func Info(v ...interface{})

func Infof

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

func Warn

func Warn(v ...interface{})

func Warnf

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

Types

type LogLevel

type LogLevel int8
const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelDisable
)

func (LogLevel) ColorEnd

func (l LogLevel) ColorEnd() string

func (LogLevel) ColorStart

func (l LogLevel) ColorStart() string

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger struct {
	Level     LogLevel
	Writer    io.Writer
	ErrWriter io.Writer

	Colors bool
	// contains filtered or unexported fields
}

func Default

func Default() *Logger

func New

func New(lvl LogLevel, writer io.Writer, errWriter io.Writer, useColors bool) *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) Warn

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

func (*Logger) Warnf

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

Directories

Path Synopsis
tests
log

Jump to

Keyboard shortcuts

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