logz

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 1 Imported by: 4

README

logz v1.0.1

Go Reference Go Report Card License

logz is a simple logging package in Go with different log levels, developed by Hazem El-Sayed

Installation

go get -u github.com/zomasec/logz

Usage

Basic Logging
package main

import (
    "github.com/zomasec/logz"
)

func main() {
    // Create a new logger
    logger := logz.DefaultLogs()

    // Log messages at different levels
    logger.INFO("This is an informational message")
    logger.DEBUG("This is a debug message")
    logger.WARNING("This is a warning message")
    logger.ERROR("This is an error message")
    logger.FATAL("This is a fatal message")
}

Custom Logging

package main

import (
    "github.com/zomasec/logz"
)

func main() {
    // Create a custom logger
    customLogger := logz.NewLogger("CUSTOM", "This is a custom message with %d args", 42)

    // Log the custom message
    customLogger.Log()
}

Customizing Logger Colors

  • To customize the colors for different log levels:

package main

import (
    "github.com/zomasec/logz"
)

func main() {
    // Creating a custom logger with a specified color
    customLogger := logz.NewLogger("DEBUG", logz.Blue, "Debugging mode activated.")
    customLogger.Log()
}

Enabling/Disabling Log Types

  • Dynamically enable or disable specific types of logs:

package main

import (
    "github.com/zomasec/logz"
)

func main() {
    logger := logz.DefaultLogs()

    // Disable DEBUG logs
    logger.DebugEnabled = false

    // This debug message will not be printed
    logger.DEBUG("This debug message will not be shown.")
}

License

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

Author

  • @ZomaSec

Documentation

Index

Constants

View Source
const (
	Red    = "\033[0;31m"
	Blue   = "\033[0;34m"
	Green  = "\033[0;32m"
	Yellow = "\033[0;33m"
	Purple = "\033[0;35m"
	NC     = "\033[0m" // No Color
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

type DefaultLogger struct {
	Level          string
	Message        string
	Args           []interface{}
	Formatter      *Formatter
	ColorEnabled   bool // Controls color output
	DebugEnabled   bool // Controls debug log visibility
	InfoEnabled    bool // Controls info log visibility
	WarningEnabled bool // Controls warning log visibility
	ErrorEnabled   bool // Controls error log visibility
	FatalEnabled   bool // Controls fatal log visibility
}

DefaultLogger now includes a map for custom log level colors.

func DefaultLogs

func DefaultLogs() *DefaultLogger

DefaultLogs returns a new DefaultLogger instance with default configuration.

func (*DefaultLogger) DEBUG

func (l *DefaultLogger) DEBUG(msg string, args ...interface{})

func (*DefaultLogger) ERROR

func (l *DefaultLogger) ERROR(msg string, args ...interface{})

func (*DefaultLogger) FATAL

func (l *DefaultLogger) FATAL(msg string, args ...interface{})

func (*DefaultLogger) INFO

func (l *DefaultLogger) INFO(msg string, args ...interface{})

func (*DefaultLogger) WARNING

func (l *DefaultLogger) WARNING(msg string, args ...interface{})

type Formatter

type Formatter struct {
	LogHolder string
	Message   string
	Args      []interface{}
	Color     string // Added to hold the color for the holder
}

Formatter represents the log message formatter including the color.

func NewLogger

func NewLogger(holder, color, msg string, args ...interface{}) *Formatter

NewLogger creates a new Logger instance with the provided log holder, message, color, and optional arguments.

func (Formatter) Format

func (f Formatter) Format() string

func (*Formatter) Log

func (f *Formatter) Log()

Log prints the formatted log message.

Jump to

Keyboard shortcuts

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