glogger

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 4 Imported by: 1

README

Glogger

Glogger is my (@4lch4) first attempt at a Go library/module. It's a simple logging library that I use in my projects. It's not meant to be used by anyone else, but if you find it useful, feel free to use it.

Usage

package main

import (
    "github.com/4lch4/glogger"
)

func main() {
    // Set the application name.
    appName := "AppName"

    // Set the log level to 0 (DEBUG).
    logLevel := 0

    // Create a new logger
    logger := glogger.NewLogger(&glogger.NewLoggerInput{
        AppName:  &appName,
        LogLevel: &logLevel,
    })


    // Log a debug message.
    logger.Debug("This is a debug message.", "main")

    // Log an info message.
    logger.Info("This is an info message.", "main")

    // Log a warning message.
    logger.Warn("This is a warning message.", "main")

    // Log an error message.
    logger.Error("This is an error message.", "main")

    // Log a fatal message.
    logger.Fatal("This is a fatal message.", "main")

    // Log a panic message.
    logger.Panic("This is a panic message.", "main")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCallingFunctionName added in v1.3.1

func GetCallingFunctionName() string

Types

type Logger

type Logger struct {
	// The name of the application using the logger.
	AppName string

	// 0 = DEBUG; 1 = INFO; 2 = WARN; 3 = ERROR; 4 = FATAL
	LogLevel int
}

func New added in v1.3.1

func New(loggerInput *NewLoggerInput) *Logger

An alias for the NewLogger function.

func NewLogger

func NewLogger(loggerInput *NewLoggerInput) *Logger

Creates a new instance of the Logger.

Parameters:

- appName: The name of the application using the logger. If nil, the default value is "Glogger".

- logLevel: 0 = Debug / 1 = Info / 2 = Warn / 3 = Error / 4 = Fatal. If nil, the default value is 0.

func (*Logger) ConvertLogLevel

func (l *Logger) ConvertLogLevel(level interface{}) string

Converts a given log level from an int to a string or from a number as a string to a log level name. For example: "0" -> "DEBUG" or "DEBUG" -> "0".

If the log level is a string then it is used as is as the map key. If the log level is an int then it is converted to a string and used as the map key. If none of the above return a value then the LogLevel property of the Logger is used as the map key.

func (*Logger) Debug

func (l *Logger) Debug(msg string, ctx *string)

Outputs a message to the console using the DEBUG log level, fmt.Println, and coloring the output bright blue.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, input ...interface{})

Outputs a message to the console using the DEBUG log level, fmt.Printf, and coloring the output bright blue.

func (*Logger) Error

func (l *Logger) Error(msg string, ctx *string)

Outputs a message to the console using the ERROR log level, fmt.Println, and coloring the output bright red.

func (*Logger) Errorf

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

Outputs a message to the console using the ERROR log level, fmt.Printf, and coloring the output bright red.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, ctx *string)

Outputs a message to the console using the FATAL log level, fmt.Println, and coloring the output bright red.

func (*Logger) Fatalf

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

Outputs a message to the console using the FATAL log level, fmt.Printf, and coloring the output bright red.

func (*Logger) Info

func (l *Logger) Info(msg string, ctx *string)

Outputs a message to the console using the INFO log level, fmt.Println, and coloring the output cyan.

func (*Logger) Infof

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

Outputs a message to the console using the INFO log level, fmt.Printf, and coloring the output cyan.

func (*Logger) Success

func (l *Logger) Success(msg string, ctx *string)

Outputs a message to the console using fmt.Println, and coloring the output bright green.

func (*Logger) Successf

func (l *Logger) Successf(format string, input ...interface{})

Outputs a message to the console using the SUCCESS log level, fmt.Printf, and coloring the output bright green.

func (*Logger) Warn

func (l *Logger) Warn(msg string, ctx *string)

Outputs a message to the console using the WARN log level, fmt.Println, and coloring the output bright yellow.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, input ...interface{})

Outputs a message to the console using the WARN log level, fmt.Printf, and coloring the output bright yellow.

type NewLoggerInput

type NewLoggerInput struct {
	// The name of the application using the logger.
	AppName *string

	// 0 = DEBUG; 1 = INFO; 2 = WARN; 3 = ERROR; 4 = FATAL
	LogLevel *int
}

Jump to

Keyboard shortcuts

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