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.
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
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)
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)
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
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")
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
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
logs messages to a file in addition to standard output.
logx.LogToFile("Log entry written to file", logx.FGRED, logx.BGGREEN, "log.txt")
We welcome contributions from the community! If you'd like to contribute to logx, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and add tests if applicable.
- Run tests and ensure they pass.
- Submit a pull request with a clear description of your changes.
We appreciate your help in improving logx.
This project is licensed under the MIT License. See the LICENSE file for details.