clog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 6 Imported by: 0

README

🚀 clog - Colored Logger for Golang

A powerful, colorful, and feature-rich logging package that provides enhanced logging capabilities with emoji indicators, color-coded output, and comprehensive debugging features.

✨ Features
  • Color-coded output with emoji indicators
  • UTC timestamps with millisecond precision
  • File and line number tracking
  • Goroutine ID tracking
  • Performance metrics logging
  • Multiple log levels with filtering
  • Panic handling with stack traces
  • Configurable output formatting
📥 Installation
go get github.com/yourusername/clog
🔰 Quick Start
package main

import "github.com/yourusername/clog"

func main() {
    // Configure logging
    clog.SetLogLevel(clog.DebugLevel)
    
    clog.Info("Starting application...")
    clog.Success("Connected to database")
    clog.Error("Failed to connect: %v", err)
}

🎯 Log Levels

  • PanicLevel - System is unusable (💥)
  • ErrorLevel - Error events (❌)
  • WarningLevel - Warning messages (⚠️)
  • InfoLevel - General information (ℹ️)
  • DebugLevel - Debug information (🔍)
  • TraceLevel - Detailed debugging (📍)
⚙️ Configuration
// Set minimum log level
clog.SetLogLevel(clog.DebugLevel)

// Enable/disable file and line info
clog.SetShowFileLine(true)

// Enable/disable goroutine ID
clog.SetShowGoroutineID(true)
📝 Example Output
  • 🚀 INIT [2024-12-11 15:04:05.123 UTC] [main.go:25] (goroutine 1) Starting service
  • ⚙️ CONFIG [2024-12-11 15:04:05.124 UTC] [main.go:26] Loading configuration
  • ℹ️ INFO [2024-12-11 15:04:05.125 UTC] [main.go:27] Processing request
  • ✅ SUCCESS [2024-12-11 15:04:05.126 UTC] [main.go:28] Request completed
  • ❌ ERROR [2024-12-11 15:04:05.127 UTC] [main.go:29] Connection failed
🎨 Log Types
  • ℹ️ INFO - General information
  • ✅ SUCCESS - Successful operations
  • 🚀 INIT - Initialization events
  • ⚙️ CONFIG - Configuration events
  • ⚠️ WARNING - Warning messages
  • ❌ ERROR - Error messages
  • 🔍 DEBUG - Debug information
  • 📍 TRACE - Trace-level debugging
  • 💥 PANIC - Critical errors
  • 📊 METRIC - Performance metrics
📋 Usage Examples

Basic Logging:

clog.Info("Processing request from %s", clientIP)
clog.Success("Request completed successfully")
clog.Warning("High memory usage: %d%%", memoryUsage)
clog.Error("Failed to connect: %v", err)

Metrics & Debug:

// Performance metrics
clog.Metric("response_time_ms", 150, "endpoint=/api/users", "method=GET")

// Debug info
clog.Debug("Request payload: %+v", payload)
clog.Trace("SQL query: %s", query)
📄 License

MIT License 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

💡 Support

For support, please open an issue in the GitHub repository.

Documentation

Overview

Package clog provides an enhanced logging system with colored output, multiple log levels, and debug features for Go applications.

Basic usage:

clog.Info("Starting application...")
clog.Success("Server started on port %d", 8080)
clog.Error("Failed to connect: %v", err)

Log Levels (from lowest to highest):

  • PanicLevel: System is unusable, halts execution
  • ErrorLevel: Error events that might still allow the application to continue running
  • WarningLevel: Warning messages for potentially harmful situations
  • InfoLevel: General informational messages about system operation
  • DebugLevel: Detailed information for debugging
  • TraceLevel: Extremely detailed debugging information

Configuration:

clog.SetLogLevel(clog.DebugLevel)
clog.SetShowFileLine(true)
clog.SetShowGoroutineID(true)

Features:

  • Colored output using emoji prefixes
  • UTC timestamp with millisecond precision
  • File and line number tracking
  • Goroutine ID tracking
  • Performance metrics logging
  • Multiple log levels with filtering
  • Panic handling with stack traces

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(format string, args ...interface{})

func Debug

func Debug(format string, args ...interface{})

New debug methods

func Error

func Error(format string, args ...interface{})

func Info

func Info(format string, args ...interface{})

Existing methods with log level support

func Init

func Init(format string, args ...interface{})

func Metric

func Metric(name string, value interface{}, tags ...string)

func Panic

func Panic(format string, args ...interface{})

func SetLogLevel

func SetLogLevel(level LogLevel)

SetLogLevel sets the current logging level

func SetShowFileLine

func SetShowFileLine(show bool)

SetShowFileLine enables/disables file and line number in logs

func SetShowGoroutineID

func SetShowGoroutineID(show bool)

SetShowGoroutineID enables/disables goroutine ID in logs

func Success

func Success(format string, args ...interface{})

func Trace

func Trace(format string, args ...interface{})

func Warning

func Warning(format string, args ...interface{})

Types

type LogLevel

type LogLevel int

LogLevel type for controlling log output

const (
	// PanicLevel logs and then calls panic()
	PanicLevel LogLevel = iota

	// ErrorLevel indicates error conditions
	ErrorLevel

	// WarningLevel indicates potentially harmful situations
	WarningLevel

	// InfoLevel indicates general operational information
	InfoLevel

	// DebugLevel indicates detailed debug information
	DebugLevel

	// TraceLevel indicates the most detailed debugging information
	TraceLevel
)

Jump to

Keyboard shortcuts

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