betalinklogger

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: CC0-1.0 Imports: 6 Imported by: 2

README

Betalink-logger is the logger used in the different microservices of the betalink infrastructure. It provides customizable logging for applications. It supports multiple logging levels, file outputs, system logs, and concurrent-safe operations. The library is designed to be extensible and integrates seamlessly with both stdout and syslog.

Features

  • Multiple Log Levels:
    • Info (INFO)
    • Warning (WARN)
    • Error (ERROR)
    • Fatal (FATAL), which exits the program after logging.
  • Custom Output Streams: Write logs to files, system log, stdout, or stderr.
  • Concurrency-Safe Logging: Thread-safe operations with sync.Mutex.
  • Configurable Logging Behavior: Enable or disable verbose logging for finer control.
  • Graceful Closing: Ensures all log writers are properly closed to avoid data loss.

Installation

go get github.com/BragdonD/betalink-logger

Usage

package main

import (
	"os"

	"github.com/BragdonD/betalink-logger"
)

func main() {
	// Initialize logger with file output
	logFile, _ := os.Create("app.log")
	logger := betalinklogger.NewLogger("MyApp", true, false, logFile)

	defer logger.Close()

	// Log messages with different severity levels
	logger.Info("This is an informational message.")
	logger.Warning("This is a warning.")
	logger.Error("This is an error.")
}

Contributing

Feel free to open issues or submit pull requests for enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogLevel

type LogLevel int

LogLevel describes the LogLevel of verbosity for info messages when using V style logging. See documentation for the V function for more information.

type LogVerbose

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

LogVerbose is type that implements Infof, etc.

func (LogVerbose) Info

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

Info is equivalent to the global Info function, guarded by the value of v.

func (LogVerbose) Infof

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

Infof is equivalent to the global Infof function, guarded by the value of v. See the documentation of V for usage.

func (LogVerbose) Infoln

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

Infoln is equivalent to the global Infoln function, guarded by the value of v. See the documentation of V for usage.

type Logger

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

A Logger represents an active logging object. Multiple Loggers can be used simultaneously even if they are using the same writers.

func NewLogger

func NewLogger(name string, LogVerbose, systemLog bool, logFile io.Writer) *Logger

NewLogger sets up logging and should be called before log functions, usually in the caller's 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 logFile passed in also satisfies io.Closer, logFile.Close will be called when closing the Logger.

func (*Logger) Close

func (l *Logger) Close()

Close closes all the underlying log writers, which will flush any cached logs. Any 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 logs with the ERROR severity. Arguments are handled in the manner of 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(0, "msg") is the same as Error("msg").

func (*Logger) Errorf

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

Errorf logs with the Error severity. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Errorln

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

Errorln logs with the ERROR severity. Arguments are handled in the manner of fmt.Println.

func (*Logger) Fatal

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

Fatal logs with the Fatal severity, and ends with os.Exit(1). Arguments are handled in the manner of 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(0, "msg") is the same as Fatal("msg").

func (*Logger) Fatalf

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

Fatalf logs with the Fatal severity, and ends with os.Exit(1). Arguments are handled in the manner of fmt.Printf.

func (*Logger) Fatalln

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

Fatalln logs with the Fatal severity, and ends with os.Exit(1). Arguments are handled in the manner of fmt.Println.

func (*Logger) Info

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

Info logs with the Info severity. Arguments are handled in the manner of 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(0, "msg") is the same as Info("msg").

func (*Logger) Infof

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

Infof logs with the Info severity. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Infoln

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

Infoln logs with the Info severity. Arguments are handled in the manner of fmt.Println.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the output flags for the Logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl LogLevel)

SetLevel sets the Logger verbosity LogLevel for LogVerbose info logging.

func (*Logger) V

func (l *Logger) V(lvl LogLevel) LogVerbose

V generates a log record depends on the setting of the LogLevel; or none default. It uses the specified Logger.

func (*Logger) Warning

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

Warning logs with the Warning severity. Arguments are handled in the manner of 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(0, "msg") is the same as Warning("msg").

func (*Logger) Warningf

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

Warningf logs with the Warning severity. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Warningln

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

Warningln logs with the Warning severity. Arguments are handled in the manner of fmt.Println.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳