gloomy

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

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 7 Imported by: 0

README ¶

Gloomy 📜

Gloomy is a simple cross platform Go logging library for Linux(mainly), and macOS, it can log to the Linux/macOS syslog, and an io.Writer.(similar to tee)

Usage 💻

Set up the default gloomy to log the system log (syslog) and a file, include a flag to turn up verbosity:

cd examples && go run main.go

The Init function returns a gloomy so you can setup multiple instances if you wish, only the first call to Init will set the default gloomy:

lf, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
if err != nil {
  gloomy.Fatalf("Failed to open log file: %v", err)
}
defer lf.Close()

// Log to system log and a log file, Info logs don't write to stdout.
loggerOne := gloomy.Init("GloomyExample", false, true, lf)
defer loggerOne.Close()
// Don't to system log or a log file, Info logs write to stdout..
loggerTwo := gloomy.Init("GloomyExample", true, false, ioutil.Discard)
defer loggerTwo.Close()

loggerOne.Info("This will log to the log file and the system log")
loggerTwo.Info("This will only log to stdout")
gloomy.Info("This is the same as using loggerOne")

Custom Format 📑

Code Example
gloomy.SetFlags(log.Ldate) [ERROR]: 2018/11/11 Error running Foobar: message
gloomy.SetFlags(log.Ltime) [ERROR]: 09:42:45 Error running Foobar: message
gloomy.SetFlags(log.Lmicroseconds) [ERROR]: 09:42:50.776015 Error running Foobar: message
gloomy.SetFlags(log.Llongfile) [ERROR]: /src/main.go:31: Error running Foobar: message
gloomy.SetFlags(log.Lshortfile) [ERROR]: main.go:31: Error running Foobar: message
gloomy.SetFlags(log.LUTC) [ERROR]: Error running Foobar: message
gloomy.SetFlags(log.LstdFlags) [ERROR]: 2018/11/11 09:43:12 Error running Foobar: message
func main() {
    lf, err := os.OpenFile(logPath, …, 0660)
    defer gloomy.Init("foo", *verbose, true, lf).Close()
    gloomy.SetFlags(log.LstdFlags)
}

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func Close ¶

func Close()

Close closes the default logger.

func Error ¶

func Error(v ...interface{})

Error level logs. Arguments according to fmt.Print.

func ErrorDepth ¶

func ErrorDepth(depth int, v ...interface{})

ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth called with depth 0 is equivalent to Error.

func Errorf ¶

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

Formatted error level logs. Arguments according to fmt.Printf.

func Errorln ¶

func Errorln(v ...interface{})

Newline appended error level logs. Arguments according to fmt.Println.

func Fatal ¶

func Fatal(v ...interface{})

Fatal level logs which terminates with os.Exit(1). Arguments according to fmt.Print.

func FatalDepth ¶

func FatalDepth(depth int, v ...interface{})

FatalDepth acts as Fatal but uses depth to determine which call frame to log. FatalDepth called with depth 0 is equivalent to Fatal.

func Fatalf ¶

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

Formatted Fatal level logs terminates with os.Exit(1). Arguments according to fmt.Printf.

func Fatalln ¶

func Fatalln(v ...interface{})

Newline appended Fatal level logs which terminates with os.Exit(1). Arguments according to fmt.Println.

func Info ¶

func Info(v ...interface{})

Info level logs. Arguments according to fmt.Print.

func InfoDepth ¶

func InfoDepth(depth int, v ...interface{})

InfoDepth acts as Info but uses depth to determine which call frame to log. InfoDepth called with depth 0 is equivalent to Info.

func Infof ¶

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

Formatted info level logs. Arguments according to fmt.Printf.

func Infoln ¶

func Infoln(v ...interface{})

Newline appended info level logs. Arguments according to fmt.Println.

func SetFlags ¶

func SetFlags(flag int)

Sets the output flags for the logger.

func SetLevel ¶

func SetLevel(lvl Level)

Sets the verbosity level for verbose info logging for the default logger.

func Warning ¶

func Warning(v ...interface{})

Warning level logs. Arguments according to fmt.Print.

func WarningDepth ¶

func WarningDepth(depth int, v ...interface{})

WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth called with depth 0 is equivalent to Warning.

func Warningf ¶

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

Formatted warning level logs. Arguments according to fmt.Printf.

func Warningln ¶

func Warningln(v ...interface{})

Newline appended warning level logs. Arguments according to fmt.Println.

Types ¶

type Level ¶

type Level int

Level describes the level of verbosity for info messages when using Verbose logging

type Logger ¶

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

Logger represents a logging object, multiple Loggers can be used simultaneously even if they are using the same writers.

func Init ¶

func Init(name string, verbose, systemLog bool, logFd io.Writer) *Logger

Init initializes logging and should be called in main(). Default log functions can be called before Init(), but log output will only go to stderr (along with a warning). The first call to Init populates the default logger and returns the generated logger, subsequent calls to Init will only return the generated logger. If the logFd passed in also satisfies io.Closer, logFd.Close will be called when closing the logger.

func (*Logger) Close ¶

func (l *Logger) Close()

Close closes all log writers and will flush any cached logs. Errors from closing the underlying log writers will be printed to stderr. Once Close is called, all future calls to the logger will panic.

func (*Logger) Error ¶

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

Error level logs. Arguments according to fmt.Print.

func (*Logger) ErrorDepth ¶

func (l *Logger) ErrorDepth(depth int, v ...interface{})

ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth called with depth 0 is equivalent to Error.

func (*Logger) Errorf ¶

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

Formatted error level logs. Arguments according to fmt.Printf.

func (*Logger) Errorln ¶

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

Newline appended error level logs. Arguments according to fmt.Println.

func (*Logger) Fatal ¶

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

Fatal level logs which terminates with os.Exit(1). Arguments according to fmt.Print.

func (*Logger) FatalDepth ¶

func (l *Logger) FatalDepth(depth int, v ...interface{})

FatalDepth acts as Fatal but uses depth to determine which call frame to log. FatalDepth called with depth 0 is equivalent to Fatal.

func (*Logger) Fatalf ¶

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

Formatted Fatal level logs terminates with os.Exit(1). Arguments according to fmt.Printf.

func (*Logger) Fatalln ¶

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

Newline appended Fatal level logs which terminates with os.Exit(1). Arguments according to fmt.Println.

func (*Logger) Info ¶

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

Info level logs. Arguments according to fmt.Print.

func (*Logger) InfoDepth ¶

func (l *Logger) InfoDepth(depth int, v ...interface{})

InfoDepth acts as Info but uses depth to determine which call frame to log. InfoDepth called with depth 0 is equivalent to Info.

func (*Logger) Infof ¶

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

Formatted info level logs. Arguments according to fmt.Printf.

func (*Logger) Infoln ¶

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

Newline appended info level logs. Arguments according to fmt.Println.

func (*Logger) SetLevel ¶

func (l *Logger) SetLevel(lvl Level)

Set the logger verbosity level for verbose info logging.

func (*Logger) Verbosity ¶

func (l *Logger) Verbosity(lvl Level) Verbose

Verbosity generates a log record depends on the setting of the Level; or none default. It uses the specified logger.

func (*Logger) Warning ¶

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

Warning level logs. Arguments according to fmt.Print.

func (*Logger) WarningDepth ¶

func (l *Logger) WarningDepth(depth int, v ...interface{})

WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth called with depth 0 is equivalent to Warning.

func (*Logger) Warningf ¶

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

Formatted warning level logs. Arguments according to fmt.Printf.

func (*Logger) Warningln ¶

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

Newline appended warning level logs. Arguments according to fmt.Println.

type Verbose ¶

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

func Verbosity ¶

func Verbosity(lvl Level) Verbose

Verbosity generates a log record, depends on the setting of the Level; or none by default using the default logger.

func (Verbose) Info ¶

func (v Verbose) Info(args ...interface{})

Info is equivalent to Info function, when verbosity(v) is enabled.

func (Verbose) Infof ¶

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

Infof is equivalent to Infof function, when verbosity(v) is enabled. See the docs of Verbosity for usage.

func (Verbose) Infoln ¶

func (v Verbose) Infoln(args ...interface{})

Infoln is equivalent to Infoln function, when verbosity(v) is enabled. See the docs of Verbosity for usage.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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