mlog

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 6 Imported by: 0

README

mlog

Minimal log which only adds Debug family functions to the standard log.

Usage

package main

import (
	log "github.com/zachcheung/mlog"
)

func main() {
	log.Debug("It's not showed by default")
	log.EnableDebug()
	log.Debug("hello world")
	log.Debugf("hello %s", "world")
	log.Debugln("hello", "world")
}

Output:

2023/01/14 19:42:02 [DEBUG] hello world
2023/01/14 19:42:02 [DEBUG] hello world
2023/01/14 19:42:02 [DEBUG] hello world

Installation

go get github.com/zachcheung/mlog

License

MIT

Author

Zach Cheung

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...any)

Debug prints with "[DEBUG] " prefix when in the debug mode. Arguments are handled in the manner of fmt.Print.

func Debugf

func Debugf(format string, v ...any)

Debugf prints with "[DEBUG] " prefix when in the debug mode. Arguments are handled in the manner of fmt.Printf.

func Debugln

func Debugln(v ...any)

Debugln prints with "[DEBUG] " prefix when in the debug mode. Arguments are handled in the manner of fmt.Println.

func DisableDebug

func DisableDebug()

DisableDebug disables the debug log mode and has higher priority than DEBUG environment variable.

func EnableDebug

func EnableDebug()

EnableDebug enables the debug log mode and has higher priority than DEBUG environment variable.

func Fatal added in v0.2.1

func Fatal(v ...any)

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf added in v0.2.1

func Fatalf(format string, v ...any)

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln added in v0.2.1

func Fatalln(v ...any)

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func Output added in v0.2.1

func Output(calldepth int, s string) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Output.

func Panic added in v0.2.1

func Panic(v ...any)

Panic is equivalent to Print() followed by a call to panic().

func Panicf added in v0.2.1

func Panicf(format string, v ...any)

Panicf is equivalent to Printf() followed by a call to panic().

func Panicln added in v0.2.1

func Panicln(v ...any)

Panicln is equivalent to Println() followed by a call to panic().

func Print added in v0.2.1

func Print(v ...any)

Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.

func Printf added in v0.2.1

func Printf(format string, v ...any)

Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Println added in v0.2.1

func Println(v ...any)

Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.

Types

type Logger

type Logger struct {
	log.Logger
	// contains filtered or unexported fields
}

A Logger is a standard log.Logger with Debug family functions.

func New

func New() *Logger

New creates a new Logger and enables the debug log mode when found DEBUG environment variable set to one of the following values:

  • yes
  • true
  • 1

func (*Logger) Debug

func (l *Logger) Debug(v ...any)

Debug prints with "[DEBUG] " prefix when in the debug mode. Arguments are handled in the manner of fmt.Print.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...any)

Debugf prints with "[DEBUG] " prefix when in the debug mode. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Debugln

func (l *Logger) Debugln(v ...any)

Debugln prints with "[DEBUG] " prefix when in the debug mode. Arguments are handled in the manner of fmt.Println.

func (*Logger) DisableDebug

func (l *Logger) DisableDebug()

DisableDebug disables the debug log mode and has higher priority than DEBUG environment variable.

func (*Logger) EnableDebug

func (l *Logger) EnableDebug()

EnableDebug enables the debug log mode and has higher priority than DEBUG environment variable.

Jump to

Keyboard shortcuts

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