termlog

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MPL-2.0 Imports: 6 Imported by: 3

README

Termlog

An opinionated logging library for terminal applications.

  • Writes to stderr by default. May write to any os.File.
  • Prints with colors and text formatting. This may be disabled, but not customized.
  • Color and formatting is automatically disabled of the output file isn't a terminal.
  • Each different type of log message has a different prefix, which cannot be changed.
  • A timestamp may be added to the log messages. This is disabled by default.
  • Thread-safe implementation.
  • Any errors encountered when writing to the log file is ignored.

Example

package main

import (
	tl "github.com/mhmorgan/termlog"
)

func main() {
	tl.Info("Hello, world!")
	
	tl.SetTimestampEnabled(true)
	tl.Error("Something went wrong!")
}

Documentation

Overview

Example
SetLogFile(os.Stdout)
Bad("Bad")
Emph("Emph")
Error("Error")
Good("Good")
Info("Info")
Warn("Warn")
Output:

[✗] Bad
[*] Emph
[!!] Error
[✓] Good
[·] Info
[!] Warn

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bad

func Bad(a ...any)

Bad writes a failure message to the log file.

func Badf added in v1.2.0

func Badf(format string, a ...any)

Badf is like Bad, but takes a format string and arguments.

func Badln added in v1.4.0

func Badln(a ...any)

Badln is like Bad.

func Emph

func Emph(a ...any)

Emph writes an emphasized message to the log file.

func Emphf added in v1.2.0

func Emphf(format string, a ...any)

Emphf is like Emph, but takes a format string and arguments.

func Emphln added in v1.4.0

func Emphln(a ...any)

Emphln is like Emph.

func Error added in v1.4.0

func Error(a ...any)

Error writes an error message to the log file.

func Errorf added in v1.4.0

func Errorf(format string, a ...any)

Errorf is like Error, but takes a format string and arguments.

func Errorln added in v1.4.0

func Errorln(a ...any)

Errorln is like Error.

func Fatal added in v1.3.0

func Fatal(a ...any)

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

func FatalIfErr added in v1.4.0

func FatalIfErr(err error)

FatalIfErr is equivalent to Fatal() if err is not nil, otherwise does nothing.

func Fatalf added in v1.3.0

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

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

func Fatalln added in v1.4.0

func Fatalln(a ...any)

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

func Good

func Good(a ...any)

Good writes a success message to the log file.

func Goodf added in v1.2.0

func Goodf(format string, a ...any)

Goodf is like Good, but takes a format string and arguments.

func Goodln added in v1.4.0

func Goodln(a ...any)

Goodln is like Good.

func Info

func Info(a ...any)

Info writes an info message to the log file.

func Infof added in v1.2.0

func Infof(format string, a ...any)

Infof is like Info, but takes a format string and arguments.

func Infoln added in v1.4.0

func Infoln(a ...any)

Infoln is like Info.

func Output added in v1.4.0

func Output(style func(string) string, prefix string, s string)

Output writes a log message to the log file. This is the most basic log function, and is used by the other log functions. May be used to write custom log messages.

The style function is used to format the message (prefix and message). If style is nil, the message is not formatted.

The prefix is the string that is printed before the message.

If timestamp is enabled, the timestamp is printed between the prefix and the message. The timestamp styling is not customizable.

A newline is added to the end of the message, unless the message already ends with a newline.

func Panic added in v1.4.0

func Panic(a ...any)

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

func PanicIfErr added in v1.4.0

func PanicIfErr(err error)

PanicIfErr is equivalent to Panic() if err is not nil, otherwise does nothing.

func Panicf added in v1.4.0

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

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

func Panicln added in v1.4.0

func Panicln(a ...any)

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

func Print added in v1.4.0

func Print(prefix string, a ...any)

Print writes a message with custom prefix, without any formatting or coloring, to the log file.

func Printf added in v1.4.0

func Printf(prefix, format string, a ...any)

Printf is like Print, but takes a format string and arguments.

func Println added in v1.4.0

func Println(prefix string, a ...any)

Println is like Print.

func SetColorsEnabled

func SetColorsEnabled(b bool)

SetColorsEnabled enables or disables colors (and bold formatting) in the log output. Colors are enabled by default.

func SetLogFile

func SetLogFile(f *os.File)

SetLogFile sets the file to write logs messages to. If the file is a TTY colors will be enabled, unless the user has explicitly disabled colors.

func SetTimestampEnabled

func SetTimestampEnabled(b bool)

SetTimestampEnabled enables or disables timestamps in the log output. Timestamps are disabled by default.

func Warn

func Warn(a ...any)

Warn writes a warning message to the log file.

func Warnf added in v1.2.0

func Warnf(format string, a ...any)

Warnf is like Warn, but takes a format string and arguments.

func Warnln added in v1.4.0

func Warnln(a ...any)

Warnln is like Warn.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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