Skip to content

ej4y/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logger

A simple and lightweight logging library for Go.

Features

  • Multiple log levels (DEBUG, INFO, WARN, ERROR)
  • Colored log output for better readability
  • Displays timestamp, file name, and line number
  • Easy to set up and use
  • Webhook support (Discord)

Installation

go get github.com/solgitae/logger

Usage

Here is a simple example of how to use logger:

package main

import (
	"github.com/solgitae/logger/model"
)

func main() {
	// Set the minimum log level.
	// Only logs with this level or higher will be printed.
	logger.Default("DEBUG")
	logger.Info("This is an info message.")
	logger.Error("This is an error message.")
	logger.Debug("This message will not be printed.")
	logger.Warn("This is a warning message.")
}

Preview

image

Log Levels

The following log levels are available:

  • DEBUG: For detailed debugging information.
  • INFO: For general informational messages.
  • WARN: For warnings that might indicate a problem.
  • ERROR: For errors that have occurred.

You can set the minimum log level using the logger.Default() function. For example, if you set the level to INFO, DEBUG messages will not be printed.

Log Format

The log output is formatted as follows:

[<LEVEL>][<file>:<line>][<timestamp>] <message>
  • <LEVEL>: The log level (e.g., INFO, ERROR).
  • <file>:<line>: The file name and line number where the log was called.
  • <timestamp>: The time when the log was created.
  • <message>: The log message.

Webhooks

logger supports sending log messages to webhooks. Currently, Discord is supported.

Discord

To send log messages to a Discord channel, you need to create a DiscordNotifier and add it to the logger.

package main

import (
	"github.com/solgitae/logger/model"
)

func main() {
	logger.Default("DEBUG")
	logger.Info("This message will be sent to Discord.")
}

About

A simple and lightweight logging library for Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages