Skip to content

Commit b89d8e6

Browse files
authored
Merge pull request #14 from cyinnove/develop
add new version of logger
2 parents 8bc0fbb + 09bd34b commit b89d8e6

File tree

8 files changed

+165
-226
lines changed

8 files changed

+165
-226
lines changed

README.md

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,109 @@
1-
## Overview
1+
# logify
22

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.
64

75
## Features
86

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.
1210

1311
## Installation
1412

15-
Install the `logify` package using `go get`:
13+
To use `logify`, install the package via `go get`:
1614

1715
```sh
18-
go get github.com/cyinnove/logify@latest
16+
go get github.com/cyinnove/logify
1917
```
2018

21-
## How to Use
19+
## Usage
2220

2321
### Importing the Package
2422

25-
Import the package in your Go application:
23+
Import the `logify` package in your Go application:
2624

2725
```go
2826
import (
29-
log "github.com/cyinnove/logify"
27+
"github.com/cyinnove/logify"
3028
)
3129
```
3230

3331
### Basic Logging
3432

35-
Example of basic logging functionality:
33+
Here's an example of basic logging:
3634

3735
```go
3836
package main
3937

4038
import (
41-
log "github.com/cyinnove/logify"
39+
"github.com/cyinnove/logify"
4240
)
4341

4442
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")
4755
}
4856
```
4957

50-
### Custom Logging
58+
### Custom Logger
5159

52-
Creating custom log messages with specified colors and formats:
60+
Create custom log messages with specified colors:
5361

5462
```go
5563
package main
5664

5765
import (
58-
log "github.com/cyinnove/logify"
66+
"github.com/cyinnove/logify"
5967
)
6068

6169
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")
6475

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")
6678
}
6779

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...)
7484
}
7585
```
7686

7787
## Log Levels
7888

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:
8790

88-
These levels help categorize and filter log messages based on severity.
89-
90-
## Logging Example
91-
92-
![Logging Example](/static/logs.png)
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.
9397

9498
## Singleton Pattern
9599

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.
97101

98102
## Contributing
99103

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.
101105

102106
## License
103107

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

colors.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +0,0 @@
1-
package logify
2-
3-
type Color int8
4-
5-
const (
6-
Red Color = iota
7-
Blue
8-
Green
9-
Yellow
10-
Purple
11-
Cyan
12-
Gray
13-
Orange
14-
Reset
15-
)
16-
17-
// Colors is a map that associates each Color with its corresponding ANSI escape code.
18-
19-
var Colors = map[Color]string{
20-
Red: "\033[0;31m",
21-
Blue: "\033[0;34m",
22-
Green: "\033[0;32m",
23-
Yellow: "\033[0;33m",
24-
Purple: "\033[0;35m",
25-
Cyan: "\033[0;36m",
26-
Gray: "\033[0;37m",
27-
Orange: "\033[0;91m",
28-
Reset: "\033[0m",
29-
}

examples/example.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package main
22

33
import (
4-
log "github.com/cyinnove/logify"
4+
"github.com/cyinnove/logify"
55
)
66

77
func main() {
8-
//host := "https://example.com"
9-
path := "docs/example.go"
10-
11-
log.Msg().Test(path)
12-
13-
CustomLogger(log.Red, "Custom", "This is a custom log message with color %s", "Red")
14-
15-
}
16-
17-
func CustomLogger(color log.Color, holder, message string, args ...interface{}) {
18-
formatter := log.Formatter{}
19-
20-
formatter.SetHolder(holder)
21-
formatter.SetMessage(message, args...)
22-
formatter.SetColor(color)
23-
formatter.Log()
24-
8+
// Set logging configuration
9+
logify.UseColors = true
10+
logify.MaxLevel = logify.Silent
11+
12+
// Example logging
13+
logify.Infof("This is an %s message", "info")
14+
logify.Warningf("This is a %s message", "warning")
15+
logify.Errorf("This is an %s message", "error")
16+
logify.Debugf("This is a %s message", "debug")
17+
logify.Verbosef("This is a verbose message with a label", "LABEL")
18+
logify.Silentf("This is a silent message")
19+
20+
// Fatal error example (uncomment to test)
21+
// logify.Fatalf("This is a fatal message, the program will exit")
2522
}

formatter.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

level.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package logify
22

3-
4-
type Level int8
3+
type Level int
54

65
const (
7-
Info Level = iota
8-
Debug
9-
Warn
10-
Error
6+
Null Level = iota
117
Fatal
12-
Test
8+
Silent
9+
Label
10+
Misc
11+
Error
12+
Info
13+
Warning
14+
Debug
15+
Verbose
1316
)
1417

15-
func (l Level) String() string {
16-
return [...]string{"INF", "DBG", "WRN", "ERR", "FTL", "TST"}[l]
17-
}
18+
var labels = map[Level]string{
19+
Warning: "WRN",
20+
Error: "ERR",
21+
Label: "WRN",
22+
Fatal: "FTL",
23+
Debug: "DBG",
24+
Info: "INF",
25+
}

0 commit comments

Comments
 (0)