theritikchoure / logx

LogX is a Go package that allows you to add color and formatting to your console log messages, making it easier to distinguish different types of log entries or to add emphasis to specific messages.

Home Page:https://pkg.go.dev/github.com/theritikchoure/logx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logx: Colorful Logging for Go

Go Report Card License GitHub Release Build Status GoDoc Coverage Status

logx is a Go package that allows you to add color and formatting to your console log messages, making it easier to distinguish different types of log entries or to add emphasis to specific messages. It provides a simple way to enhance your application's log output.

Table of Contents

Installation

To use logx, you need to import it in your Go code:

import "github.com/theritikchoure/logx"

Then, install it with go get:

go get github.com/theritikchoure/logx

Usage

Enabling or Disabling Color

By default, colorized logging is disabled. You can enable or disable it by modifying the ColoringEnabled variable in your code. Setting it to true will enable colored output, and setting it to false will disable it.

logx.ColoringEnabled = true // Enable colorized logging
logx.ColoringEnabled = false // Disable colorized logging (default)

Log

The Log function allows you to print log messages with specified foreground and background colors. If coloring is disabled, it will print plain text.

logx.Log("This is a log message", logx.FGRED, logx.BGGREEN)

Logf

Use Logf to format log messages and specify colors. It is similar to fmt.Printf.

logx.Logf("User: %s logged in.", logx.FGBLUE, logx.BGWHITE, "JohnDoe")

LogWithLevel

LogWithLevel is helpful for displaying log messages with predefined background colors corresponding to log levels such as INFO, WARNING, ERROR, and SUCCESS.

logx.LogWithLevel("An error occurred", "ERROR")

LogM

With LogM, you can log multiple messages with customized formatting options.

logx.LogM([]string{"Applying", "updates..."}, logx.FGBLUE, logx.BGYELLOW, logx.BOLD, logx.UNDERLINE)

LogWithTimestamp

LogWithTimestamp adds a timestamp to your log message. It's particularly useful for recording when an event occurred.

logx.LogWithTimestamp("System restarted", logx.FGCYAN, logx.BGWHITE)

LogToFile

LogToFile logs messages to a file in addition to standard output.

logx.LogToFile("Log entry written to file", logx.FGRED, logx.BGGREEN, "log.txt")

Guide

Contributing

We welcome contributions from the community! If you'd like to contribute to logx, follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and add tests if applicable.
  4. Run tests and ensure they pass.
  5. Submit a pull request with a clear description of your changes.

We appreciate your help in improving logx.

License

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

About

LogX is a Go package that allows you to add color and formatting to your console log messages, making it easier to distinguish different types of log entries or to add emphasis to specific messages.

https://pkg.go.dev/github.com/theritikchoure/logx

License:MIT License


Languages

Language:Go 100.0%