-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from cyinnove/develop
add new version of logger
- Loading branch information
Showing
8 changed files
with
165 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,109 @@ | ||
## Overview | ||
# logify | ||
|
||
This tool provides a custom logging solution for Go applications using the `logify` package. It supports various log levels such as INFO, TEST, DEBUG, FATAL, ERROR, and WARN, and allows for custom log messages with specified colors and formats. The logger follows the Singleton pattern to ensure a consistent logging instance throughout the application. | ||
|
||
This logging package is versatile, suitable for CLI tools, security tools, web servers, and more, offering robust and customizable logging capabilities. | ||
`logify` is a customizable logging solution for Go applications that supports various log levels and custom formatting. This package offers flexibility in logging messages with different levels of severity, colors, and formats. It uses a simple and efficient approach to logging by providing a single instance of the logger across the application. | ||
|
||
## Features | ||
|
||
- **Log Levels**: INFO, TEST, DEBUG, FATAL, ERROR, WARN. | ||
- **Custom Logger**: Custom log messages with specified colors and formats. | ||
- **Singleton Pattern**: Single logger instance throughout the application. | ||
- **Log Levels**: Supports multiple log levels including `INFO`, `DEBUG`, `ERROR`, `FATAL`, `WARNING`, and `SILENT`. | ||
- **Custom Colors**: Allows custom log messages with specified colors. | ||
- **Singleton Pattern**: Ensures a single logger instance is used throughout the application for consistency. | ||
|
||
## Installation | ||
|
||
Install the `logify` package using `go get`: | ||
To use `logify`, install the package via `go get`: | ||
|
||
```sh | ||
go get github.com/cyinnove/logify@latest | ||
go get github.com/cyinnove/logify | ||
``` | ||
|
||
## How to Use | ||
## Usage | ||
|
||
### Importing the Package | ||
|
||
Import the package in your Go application: | ||
Import the `logify` package in your Go application: | ||
|
||
```go | ||
import ( | ||
log "github.com/cyinnove/logify" | ||
"github.com/cyinnove/logify" | ||
) | ||
``` | ||
|
||
### Basic Logging | ||
|
||
Example of basic logging functionality: | ||
Here's an example of basic logging: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
log "github.com/cyinnove/logify" | ||
"github.com/cyinnove/logify" | ||
) | ||
|
||
func main() { | ||
path := "docs/example.go" | ||
log.Msg().Warn(path) | ||
logify.UseColors = true | ||
logify.MaxLevel = logify.Debug | ||
|
||
logify.Infof("This is an %s message", "info") | ||
logify.Warningf("This is a %s message", "warning") | ||
logify.Errorf("This is an %s message", "error") | ||
logify.Debugf("This is a %s message", "debug") | ||
logify.Verbosef("This is a verbose message with a label", "LABEL") | ||
logify.Silentf("This is a silent message") | ||
|
||
// Uncomment to test Fatalf | ||
// logify.Fatalf("This is a fatal message, the program will exit") | ||
} | ||
``` | ||
|
||
### Custom Logging | ||
### Custom Logger | ||
|
||
Creating custom log messages with specified colors and formats: | ||
Create custom log messages with specified colors: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
log "github.com/cyinnove/logify" | ||
"github.com/cyinnove/logify" | ||
) | ||
|
||
func main() { | ||
path := "examples/example.go" | ||
log.Msg().Warn(path) | ||
logify.UseColors = true | ||
logify.MaxLevel = logify.Debug | ||
|
||
// Default logging | ||
logify.Warningf("Default warning message") | ||
|
||
CustomLogger(log.Red, "Custom", "This is a custom log message with color %s", "Red") | ||
// Custom logging | ||
CustomLogger(logify.Red, "CustomLabel", "This is a custom log message with color %s", "Red") | ||
} | ||
|
||
func CustomLogger(color log.Color, holder, message string, args ...interface{}) { | ||
formatter := log.Formatter{} | ||
formatter.SetHolder(holder) | ||
formatter.SetMessage(message, args...) | ||
formatter.SetColor(color) | ||
formatter.Log() | ||
func CustomLogger(color logify.Color, label, format string, args ...interface{}) { | ||
logify.UseColors = true | ||
logify.MaxLevel = logify.Debug | ||
logify.Printf(format, args...) | ||
} | ||
``` | ||
|
||
## Log Levels | ||
|
||
The logger supports the following log levels: | ||
|
||
- **INFO** | ||
- **TEST** | ||
- **DEBUG** | ||
- **FATAL** | ||
- **ERROR** | ||
- **WARN** | ||
The logger supports the following levels: | ||
|
||
These levels help categorize and filter log messages based on severity. | ||
|
||
## Logging Example | ||
|
||
![Logging Example](/static/logs.png) | ||
- **INFO**: Informational messages. | ||
- **DEBUG**: Debugging messages. | ||
- **ERROR**: Error messages. | ||
- **FATAL**: Fatal errors that cause application exit. | ||
- **WARNING**: Warning messages. | ||
- **SILENT**: Messages with no label. | ||
|
||
## Singleton Pattern | ||
|
||
The logger ensures a single instance across the entire application, maintaining consistency and avoiding issues with multiple instances. | ||
The logger follows the Singleton pattern to maintain a single instance throughout the application, ensuring consistent logging behavior and avoiding multiple instances. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Submit a pull request or open an issue for suggestions or bug reports. | ||
Contributions are welcome! To contribute, please submit a pull request or open an issue with your suggestions or bug reports. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the LICENSE file for details. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +0,0 @@ | ||
package logify | ||
|
||
type Color int8 | ||
|
||
const ( | ||
Red Color = iota | ||
Blue | ||
Green | ||
Yellow | ||
Purple | ||
Cyan | ||
Gray | ||
Orange | ||
Reset | ||
) | ||
|
||
// Colors is a map that associates each Color with its corresponding ANSI escape code. | ||
|
||
var Colors = map[Color]string{ | ||
Red: "\033[0;31m", | ||
Blue: "\033[0;34m", | ||
Green: "\033[0;32m", | ||
Yellow: "\033[0;33m", | ||
Purple: "\033[0;35m", | ||
Cyan: "\033[0;36m", | ||
Gray: "\033[0;37m", | ||
Orange: "\033[0;91m", | ||
Reset: "\033[0m", | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
log "github.com/cyinnove/logify" | ||
"github.com/cyinnove/logify" | ||
) | ||
|
||
func main() { | ||
//host := "https://example.com" | ||
path := "docs/example.go" | ||
|
||
log.Msg().Test(path) | ||
|
||
CustomLogger(log.Red, "Custom", "This is a custom log message with color %s", "Red") | ||
|
||
} | ||
|
||
func CustomLogger(color log.Color, holder, message string, args ...interface{}) { | ||
formatter := log.Formatter{} | ||
|
||
formatter.SetHolder(holder) | ||
formatter.SetMessage(message, args...) | ||
formatter.SetColor(color) | ||
formatter.Log() | ||
|
||
// Set logging configuration | ||
logify.UseColors = true | ||
logify.MaxLevel = logify.Silent | ||
|
||
// Example logging | ||
logify.Infof("This is an %s message", "info") | ||
logify.Warningf("This is a %s message", "warning") | ||
logify.Errorf("This is an %s message", "error") | ||
logify.Debugf("This is a %s message", "debug") | ||
logify.Verbosef("This is a verbose message with a label", "LABEL") | ||
logify.Silentf("This is a silent message") | ||
|
||
// Fatal error example (uncomment to test) | ||
// logify.Fatalf("This is a fatal message, the program will exit") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
package logify | ||
|
||
|
||
type Level int8 | ||
type Level int | ||
|
||
const ( | ||
Info Level = iota | ||
Debug | ||
Warn | ||
Error | ||
Null Level = iota | ||
Fatal | ||
Test | ||
Silent | ||
Label | ||
Misc | ||
Error | ||
Info | ||
Warning | ||
Debug | ||
Verbose | ||
) | ||
|
||
func (l Level) String() string { | ||
return [...]string{"INF", "DBG", "WRN", "ERR", "FTL", "TST"}[l] | ||
} | ||
var labels = map[Level]string{ | ||
Warning: "WRN", | ||
Error: "ERR", | ||
Label: "WRN", | ||
Fatal: "FTL", | ||
Debug: "DBG", | ||
Info: "INF", | ||
} |
Oops, something went wrong.