waterlog

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: Apache-2.0 Imports: 8 Imported by: 19

README

waterlog

Go Logging that just works

Go Report Card GoDoc license

Motivation

Logging is terribly boring, but can be an important part of a project. This library provides logging capabilities that attempt to "spice up" what is otherwise a very utilitarian aspect of programming.

Goals
  • Styling that is easy to look at
  • More granular logging severities ("levels")
  • Compatibility with the existing log.Logger interface

Implementation

Waterlog consists of two sets of code. The first is an implementation in Go which is able to be used as a drop-in replacement for the Go log.Logger. The second is a set of Makefile definitions that provide similar styling for GNU Make project.

Message Types

The traditional log.Logger implementation only provides three different message types:

Type Behavior
Fatal Log message and os.Exit(1)
Panic Log message and panic()
Print Log message

For each level it also supports a Print, Printf, and Println variant of the output.

Waterlog, on the other hand, provides a total of 8 message types. These levels also support Print, Printf, and Println output modes. Unlike log.Logger, Waterlog supports logging levels which correspond with these message types. Higher levels allow more types of message to be shown. The logging level may be changed at any time by the SetLevel() method. The psuedo-type Disable is also provided to allow quiet operation. A default level of Fatal is assigned to new Waterlog instances. Lastly, Print messages are always written as unformatted text with no timestamp and ignore the logging level.

Type Behavior Level
Disable No messages 0
Panic Runtime "exception" message and panic() 1
Fatal Unrecoverable error message and os.Exit(1) 2
Error Recoverable error message 3
Warn Warning message 4
Good Success message 5
Info General information message 6
Debug Developer Debug information. 7
Print Always print unstyled text n/a

Examples

format.Full Logger

Go format.Full Example

format.Min Logger

Go format.Min Example

format.Un Logger

Go format.Un Example

Makefile

Makefile Example

License

Copyright 2017-2021 Bryan T. Meyers [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package waterlog provides an extended and styled log.Logger functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug added in v1.0.5

func Debug(v ...interface{})

Debug is a styled Print

func Debugf added in v1.0.5

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

Debugf is a styled Printf

func Debugln added in v1.0.5

func Debugln(v ...interface{})

Debugln is a styled Println

func Error added in v1.0.5

func Error(v ...interface{})

Error is a styled Print

func Errorf added in v1.0.5

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

Errorf is a styled Printf

func Errorln added in v1.0.5

func Errorln(v ...interface{})

Errorln is a styled Println

func Fatal added in v1.0.5

func Fatal(v ...interface{})

Fatal is a styled Print followed by os.Exit(1)

func Fatalf added in v1.0.5

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

Fatalf is a styled Printf followed by os.Exit(1)

func Fatalln added in v1.0.5

func Fatalln(v ...interface{})

Fatalln is a styled Println followed by os.Exit(1)

func Flags added in v1.0.5

func Flags() int

Flags returns the output flags for std

func Good added in v1.0.5

func Good(v ...interface{})

Good is a styled Print

func Goodf added in v1.0.5

func Goodf(f string, v ...interface{})

Goodf is a styled Printf

func Goodln added in v1.0.5

func Goodln(v ...interface{})

Goodln is a styled Println

func Info added in v1.0.5

func Info(v ...interface{})

Info is a styled Print

func Infof added in v1.0.5

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

Infof is a styled Printf

func Infoln added in v1.0.5

func Infoln(v ...interface{})

Infoln is a styled Println

func Level added in v1.0.5

func Level() uint8

Level returns the logging level

func Panic added in v1.0.5

func Panic(v ...interface{})

Panic is a styled Print followed by a call to panic("")

func Panicf added in v1.0.5

func Panicf(f string, v ...interface{})

Panicf is a styled Printf followed by a call to panic("")

func Panicln added in v1.0.5

func Panicln(v ...interface{})

Panicln is a styled Println followed by a call to panic("")

func Print added in v1.0.5

func Print(v ...interface{})

Print is a mutex protect fmt.Fprint

func Printf added in v1.0.5

func Printf(f string, v ...interface{})

Printf is a mutex protect fmt.Fprintf

func Println added in v1.0.5

func Println(v ...interface{})

Println is a mutex protect fmt.Fprintln

func SetFlags added in v1.0.5

func SetFlags(flag int)

SetFlags replaces the output flags

func SetFormat added in v1.0.5

func SetFormat(format format.Func)

SetFormat changes the printing format

func SetLevel added in v1.0.5

func SetLevel(level uint8)

SetLevel changes the logging level

func SetOutput added in v1.0.5

func SetOutput(output io.Writer)

SetOutput replaces the internal io.Writer

func Warn added in v1.0.5

func Warn(v ...interface{})

Warn is a styled Print

func Warnf added in v1.0.5

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

Warnf is a styled Printf

func Warnln added in v1.0.5

func Warnln(v ...interface{})

Warnln is a styled Println

Types

type WaterLog

type WaterLog struct {
	// contains filtered or unexported fields
}

WaterLog is a styled log.Logger

func New

func New(out io.Writer, prefix string, flag int) *WaterLog

New creates a WaterLog

func (*WaterLog) Debug

func (w *WaterLog) Debug(v ...interface{})

Debug is a styled Print

func (*WaterLog) Debugf

func (w *WaterLog) Debugf(f string, v ...interface{})

Debugf is a styled Printf

func (*WaterLog) Debugln

func (w *WaterLog) Debugln(v ...interface{})

Debugln is a styled Println

func (*WaterLog) Error

func (w *WaterLog) Error(v ...interface{})

Error is a styled Print

func (*WaterLog) Errorf

func (w *WaterLog) Errorf(f string, v ...interface{})

Errorf is a styled Printf

func (*WaterLog) Errorln

func (w *WaterLog) Errorln(v ...interface{})

Errorln is a styled Println

func (*WaterLog) Fatal

func (w *WaterLog) Fatal(v ...interface{})

Fatal is a styled Print followed by os.Exit(1)

func (*WaterLog) Fatalf

func (w *WaterLog) Fatalf(f string, v ...interface{})

Fatalf is a styled Printf followed by os.Exit(1)

func (*WaterLog) Fatalln

func (w *WaterLog) Fatalln(v ...interface{})

Fatalln is a styled Println followed by os.Exit(1)

func (*WaterLog) Flags

func (w *WaterLog) Flags() int

Flags returns the output flags

func (*WaterLog) Good

func (w *WaterLog) Good(v ...interface{})

Good is a styled Print

func (*WaterLog) Goodf

func (w *WaterLog) Goodf(f string, v ...interface{})

Goodf is a styled Printf

func (*WaterLog) Goodln

func (w *WaterLog) Goodln(v ...interface{})

Goodln is a styled Println

func (*WaterLog) Info

func (w *WaterLog) Info(v ...interface{})

Info is a styled Print

func (*WaterLog) Infof

func (w *WaterLog) Infof(f string, v ...interface{})

Infof is a styled Printf

func (*WaterLog) Infoln

func (w *WaterLog) Infoln(v ...interface{})

Infoln is a styled Println

func (*WaterLog) Level

func (w *WaterLog) Level() uint8

Level returns the logging level

func (*WaterLog) Output

func (w *WaterLog) Output(calldepth int, s string) error

Output just calls Print

func (*WaterLog) Panic

func (w *WaterLog) Panic(v ...interface{})

Panic is a styled Print followed by a call to panic("")

func (*WaterLog) Panicf

func (w *WaterLog) Panicf(f string, v ...interface{})

Panicf is a styled Printf followed by a call to panic("")

func (*WaterLog) Panicln

func (w *WaterLog) Panicln(v ...interface{})

Panicln is a styled Println followed by a call to panic("")

func (*WaterLog) Print

func (w *WaterLog) Print(v ...interface{})

Print is a mutex protect fmt.Fprint

func (*WaterLog) Printf

func (w *WaterLog) Printf(f string, v ...interface{})

Printf is a mutex protect fmt.Fprintf

func (*WaterLog) Println

func (w *WaterLog) Println(v ...interface{})

Println is a mutex protect fmt.Fprintln

func (*WaterLog) SetFlags

func (w *WaterLog) SetFlags(flag int)

SetFlags replaces the output flags

func (*WaterLog) SetFormat

func (w *WaterLog) SetFormat(format format.Func)

SetFormat changes the printing format

func (*WaterLog) SetLevel

func (w *WaterLog) SetLevel(level uint8)

SetLevel changes the logging level

func (*WaterLog) SetOutput

func (w *WaterLog) SetOutput(output io.Writer)

SetOutput replaces the internal io.Writer

func (*WaterLog) Time

func (w *WaterLog) Time() string

Time returns a formatted Timestamp for logging

func (*WaterLog) Warn

func (w *WaterLog) Warn(v ...interface{})

Warn is a styled Print

func (*WaterLog) Warnf

func (w *WaterLog) Warnf(f string, v ...interface{})

Warnf is a styled Printf

func (*WaterLog) Warnln

func (w *WaterLog) Warnln(v ...interface{})

Warnln is a styled Println

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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