|
1 |
| -## Overview |
| 1 | +# logify |
2 | 2 |
|
3 |
| -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. |
4 |
| - |
5 |
| -This logging package is versatile, suitable for CLI tools, security tools, web servers, and more, offering robust and customizable logging capabilities. |
| 3 | +`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. |
6 | 4 |
|
7 | 5 | ## Features
|
8 | 6 |
|
9 |
| -- **Log Levels**: INFO, TEST, DEBUG, FATAL, ERROR, WARN. |
10 |
| -- **Custom Logger**: Custom log messages with specified colors and formats. |
11 |
| -- **Singleton Pattern**: Single logger instance throughout the application. |
| 7 | +- **Log Levels**: Supports multiple log levels including `INFO`, `DEBUG`, `ERROR`, `FATAL`, `WARNING`, and `SILENT`. |
| 8 | +- **Custom Colors**: Allows custom log messages with specified colors. |
| 9 | +- **Singleton Pattern**: Ensures a single logger instance is used throughout the application for consistency. |
12 | 10 |
|
13 | 11 | ## Installation
|
14 | 12 |
|
15 |
| -Install the `logify` package using `go get`: |
| 13 | +To use `logify`, install the package via `go get`: |
16 | 14 |
|
17 | 15 | ```sh
|
18 |
| -go get github.com/cyinnove/logify@latest |
| 16 | +go get github.com/cyinnove/logify |
19 | 17 | ```
|
20 | 18 |
|
21 |
| -## How to Use |
| 19 | +## Usage |
22 | 20 |
|
23 | 21 | ### Importing the Package
|
24 | 22 |
|
25 |
| -Import the package in your Go application: |
| 23 | +Import the `logify` package in your Go application: |
26 | 24 |
|
27 | 25 | ```go
|
28 | 26 | import (
|
29 |
| - log "github.com/cyinnove/logify" |
| 27 | + "github.com/cyinnove/logify" |
30 | 28 | )
|
31 | 29 | ```
|
32 | 30 |
|
33 | 31 | ### Basic Logging
|
34 | 32 |
|
35 |
| -Example of basic logging functionality: |
| 33 | +Here's an example of basic logging: |
36 | 34 |
|
37 | 35 | ```go
|
38 | 36 | package main
|
39 | 37 |
|
40 | 38 | import (
|
41 |
| - log "github.com/cyinnove/logify" |
| 39 | + "github.com/cyinnove/logify" |
42 | 40 | )
|
43 | 41 |
|
44 | 42 | func main() {
|
45 |
| - path := "docs/example.go" |
46 |
| - log.Msg().Warn(path) |
| 43 | + logify.UseColors = true |
| 44 | + logify.MaxLevel = logify.Debug |
| 45 | + |
| 46 | + logify.Infof("This is an %s message", "info") |
| 47 | + logify.Warningf("This is a %s message", "warning") |
| 48 | + logify.Errorf("This is an %s message", "error") |
| 49 | + logify.Debugf("This is a %s message", "debug") |
| 50 | + logify.Verbosef("This is a verbose message with a label", "LABEL") |
| 51 | + logify.Silentf("This is a silent message") |
| 52 | + |
| 53 | + // Uncomment to test Fatalf |
| 54 | + // logify.Fatalf("This is a fatal message, the program will exit") |
47 | 55 | }
|
48 | 56 | ```
|
49 | 57 |
|
50 |
| -### Custom Logging |
| 58 | +### Custom Logger |
51 | 59 |
|
52 |
| -Creating custom log messages with specified colors and formats: |
| 60 | +Create custom log messages with specified colors: |
53 | 61 |
|
54 | 62 | ```go
|
55 | 63 | package main
|
56 | 64 |
|
57 | 65 | import (
|
58 |
| - log "github.com/cyinnove/logify" |
| 66 | + "github.com/cyinnove/logify" |
59 | 67 | )
|
60 | 68 |
|
61 | 69 | func main() {
|
62 |
| - path := "examples/example.go" |
63 |
| - log.Msg().Warn(path) |
| 70 | + logify.UseColors = true |
| 71 | + logify.MaxLevel = logify.Debug |
| 72 | + |
| 73 | + // Default logging |
| 74 | + logify.Warningf("Default warning message") |
64 | 75 |
|
65 |
| - CustomLogger(log.Red, "Custom", "This is a custom log message with color %s", "Red") |
| 76 | + // Custom logging |
| 77 | + CustomLogger(logify.Red, "CustomLabel", "This is a custom log message with color %s", "Red") |
66 | 78 | }
|
67 | 79 |
|
68 |
| -func CustomLogger(color log.Color, holder, message string, args ...interface{}) { |
69 |
| - formatter := log.Formatter{} |
70 |
| - formatter.SetHolder(holder) |
71 |
| - formatter.SetMessage(message, args...) |
72 |
| - formatter.SetColor(color) |
73 |
| - formatter.Log() |
| 80 | +func CustomLogger(color logify.Color, label, format string, args ...interface{}) { |
| 81 | + logify.UseColors = true |
| 82 | + logify.MaxLevel = logify.Debug |
| 83 | + logify.Printf(format, args...) |
74 | 84 | }
|
75 | 85 | ```
|
76 | 86 |
|
77 | 87 | ## Log Levels
|
78 | 88 |
|
79 |
| -The logger supports the following log levels: |
80 |
| - |
81 |
| -- **INFO** |
82 |
| -- **TEST** |
83 |
| -- **DEBUG** |
84 |
| -- **FATAL** |
85 |
| -- **ERROR** |
86 |
| -- **WARN** |
| 89 | +The logger supports the following levels: |
87 | 90 |
|
88 |
| -These levels help categorize and filter log messages based on severity. |
89 |
| - |
90 |
| -## Logging Example |
91 |
| - |
92 |
| - |
| 91 | +- **INFO**: Informational messages. |
| 92 | +- **DEBUG**: Debugging messages. |
| 93 | +- **ERROR**: Error messages. |
| 94 | +- **FATAL**: Fatal errors that cause application exit. |
| 95 | +- **WARNING**: Warning messages. |
| 96 | +- **SILENT**: Messages with no label. |
93 | 97 |
|
94 | 98 | ## Singleton Pattern
|
95 | 99 |
|
96 |
| -The logger ensures a single instance across the entire application, maintaining consistency and avoiding issues with multiple instances. |
| 100 | +The logger follows the Singleton pattern to maintain a single instance throughout the application, ensuring consistent logging behavior and avoiding multiple instances. |
97 | 101 |
|
98 | 102 | ## Contributing
|
99 | 103 |
|
100 |
| -Contributions are welcome! Submit a pull request or open an issue for suggestions or bug reports. |
| 104 | +Contributions are welcome! To contribute, please submit a pull request or open an issue with your suggestions or bug reports. |
101 | 105 |
|
102 | 106 | ## License
|
103 | 107 |
|
104 | 108 | This project is licensed under the MIT License. See the LICENSE file for details.
|
| 109 | + |
0 commit comments