Giter Club home page Giter Club logo

theritikchoure / logx Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 29 KB

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

License: MIT License

Go 100.00%
ansi color coloring go go-lang golang logx hacktoberfest hacktoberfest-accepted

logx's Introduction

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.

logx's People

Contributors

theritikchoure avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.