golog

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: Apache-2.0 Imports: 13 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GoLog

GoLog is a logger for GoLang, designed to provide flexible and easy-to-use logging capabilities for Go projects. It aims to simplify logging tasks while offering customization options to suit various project requirements.

Installation 🛠

You can install GoLog as a project dependency using go get:

go get -u github.com/blackmamoth/GoLog

How It Works ⚙

GoLog simplifies logging tasks by providing convenient methods for logging messages at various severity levels, including TRACE, DEBUG, INFO, WARN, ERROR, and CRITICAL. Additionally, it offers the following customization options:

  • New(): Creates a new GoLog instance for logging.

  • Set_Log_Level(log_level LOG_LEVEL): Sets the minimum log level.

  • Set_Log_Format(log_format string): Updates the log format displayed. The default format is [%(asctime)] %(levelname) - [%(filename).%(lineno)]: %(message).

  • Set_Log_Stream(log_stream LOG_STREAM): Sets the log stream to console, log file, or both.

  • Set_Datetime_Format(format string): Sets the format string for time representation in logs. The default format is Mon, 02 Jan, 2006 15:04:05.

  • Set_File_Name(file_name string): Sets the log file name. The default is access.log.

  • Set_Max_File_Size(max_size int64): Sets the maximum size for a log file. If exceeded, the current log file is archived, and a new one is created. The default size is 50 * 1024 * 1024 bytes.

  • Set_Max_Days(max_days int): Sets the maximum number of days a log file should store logs. If exceeded, the current file is archived, and a new one is created.

  • Zip_Archive(zip_archive bool): Specifies whether a log file should be archived while it is rotated. If false, the current log file will be removed, and a new one will be generated.

  • With_Emoji(with_emoji bool): Specifies whether log statements should contain emoji.

  • Exit_On_Critical(exit bool): Specifies whether program should exit on a critical log.

Example Usage 📝

package main

import (
	golog "github.com/blackmamoth/GoLog"
)

func main() {
	// Initialize the logger
	logger := golog.New()

	// Set logging level
	logger.Set_Log_Level(golog.LOG_LEVEL_DEBUG)

	// Set log format
	logger.Set_Log_Format("[%(asctime)] %(levelname) - %(message)")

	// Set log stream
	logger.Set_Log_Stream(golog.LOG_STREAM_MULTIPLE)

	// Set max size
	logger.Set_Max_File_Size(10 * 1024 * 1024)

	// Make use of emojis in log statement
	logger.With_Emoji(true)

	// Log messages
	logger.DEBUG("Debug message")
	logger.INFO("Info message")
	logger.WARN("Warning message")
	logger.ERROR("Error message")
	logger.CRITICAL("Critical message")
}

Planned/Pending Features 📅

  • DRY principle

  • Thread safe logging

  • Write tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *logger

Types

type LOG_LEVEL

type LOG_LEVEL int
const (
	LOG_LEVEL_TRACE LOG_LEVEL = iota + 1
	LOG_LEVEL_DEBUG
	LOG_LEVEL_INFO
	LOG_LEVEL_WARN
	LOG_LEVEL_ERROR
	LOG_LEVEL_CRITICAL
)

type LOG_STREAM

type LOG_STREAM int
const (
	LOG_STREAM_CONSOLE LOG_STREAM = iota + 1
	LOG_STREAM_FILE
	LOG_STREAM_MULTIPLE
)

type Logger added in v0.4.0

type Logger interface {
	Set_Log_Level(log_level LOG_LEVEL)
	Set_Log_Format(log_format string)
	Set_Log_Stream(log_stream LOG_STREAM)
	Set_Datetime_Format(format string)
	Set_File_Name(file_name string)
	Set_Max_File_Size(max_size int64)
	Set_Max_Days(max_days int)
	Zip_Archive(zip_archive bool)
	With_Emoji(with_emoji bool)
	Exit_On_Critical(exit bool)
	TRACE(msg string, a ...interface{})
	DEBUG(msg string, a ...interface{})
	INFO(msg string, a ...interface{})
	WARN(msg string, a ...interface{})
	ERROR(msg string, a ...interface{})
	CRITICAL(msg string, a ...interface{})
}

Jump to

Keyboard shortcuts

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