log

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: MIT Imports: 2 Imported by: 7

README

Usage 🚀

Importing the Package 📦

First, import the package in your Go file:

import "github.com/catalystgo/logger/cli

Setting Log Level 📏

You can set the current log level using the SetLevel function. The available log levels are:

  • LevelDebug
  • LevelInfo
  • LevelWarn
  • LevelError
  • LevelFatal

For example, to set the log level to LevelDebug:

log.SetLevel(log.LevelDebug)

Logging Messages 📝

You can log messages at different levels using the following functions:

  • Debug(msg string)
  • Debugf(msg string, args ...interface{})
  • Info(msg string)
  • Infof(msg string, args ...interface{})
  • Warn(msg string)
  • Warnf(msg string, args ...interface{})
  • Error(msg string)
  • Errorf(msg string, args ...interface{})
  • Fatal(msg string)
  • Fatalf(msg string, args ...interface{})

Each log level has its own prefix and color:

Log Levels

Examples 🚀

Here are some examples of how to use the logging functions:

log.SetLevel(log.LevelDebug)

log.Debug("This is a debug message")
log.Debugf("This is a debug message with a variable: %d", 42)

log.Info("This is an info message")
log.Infof("This is an info message with a variable: %d", 42)

log.Warn("This is a warning message")
log.Warnf("This is a warning message with a variable: %d", 42)

log.Error("This is an error message")
log.Errorf("This is an error message with a variable: %d", 42)

log.Fatal("This is a fatal message")
log.Fatalf("This is a fatal message with a variable: %d", 42)

// Panic functions can't be disabled by setting the log level to a higher value
// since they are meant to be used in critical situations where the application can't continue

log.Panic("This is a panic message")
log.Panicf("This is a panic message with a variable: %d", 42)

Documentation

Index

Constants

View Source
const (
	LevelDebug level = 0
	LevelInfo  level = 1
	LevelWarn  level = 2
	LevelError level = 3
	LevelFatal level = 4
)

Variables

This section is empty.

Functions

func Debug

func Debug(msg string)

func Debugf

func Debugf(msg string, args ...interface{})

func Error

func Error(msg string)

func Errorf

func Errorf(msg string, args ...interface{})

func Fatal

func Fatal(msg string)

func Fatalf

func Fatalf(msg string, args ...interface{})

func Info

func Info(msg string)

func Infof

func Infof(msg string, args ...interface{})

func Panic

func Panic(msg string)

func Panicf

func Panicf(msg string, args ...interface{})

func SetLevel

func SetLevel(l level)

func Warn

func Warn(msg string)

func Warnf

func Warnf(msg string, args ...interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

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