Skip to content

Commit 0953290

Browse files
committed
feat: improved logger support
1 parent 4db7b1c commit 0953290

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

log/face.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package logger
22

3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
38
type logger struct{}
49

510
// Logger returns a new barf logger instance
@@ -12,22 +17,59 @@ func (l *logger) Info(msg string) {
1217
Info(msg)
1318
}
1419

20+
// Infof logs a formatted message with the green color
21+
func (l *logger) Infof(msg string, v ...interface{}) {
22+
Info(fmt.Sprintf(msg, v...))
23+
}
24+
1525
// Error logs a message with the red color
1626
func (l *logger) Error(msg string) {
1727
Error(msg)
1828
}
1929

30+
// Errorf logs a formatted message with the red color
31+
func (l *logger) Errorf(msg string, v ...interface{}) {
32+
Error(fmt.Sprintf(msg, v...))
33+
}
34+
35+
// Fatal logs a message with the red color and exits the program
36+
func (l *logger) Fatal(msg string) {
37+
Error(msg)
38+
os.Exit(1)
39+
}
40+
41+
// Fatalf logs a formatted message with the red color and exits the program
42+
func (l *logger) Fatalf(msg string, v ...interface{}) {
43+
Error(fmt.Sprintf(msg, v...))
44+
os.Exit(1)
45+
}
46+
2047
// Debug logs a message with the blue color
2148
func (l *logger) Debug(msg string) {
2249
Debug(msg)
2350
}
2451

52+
// Debugf logs a formatted message with the blue color
53+
func (l *logger) Debugf(msg string, v ...interface{}) {
54+
Debug(fmt.Sprintf(msg, v...))
55+
}
56+
2557
// Code is a function that logs based on the status code
2658
func (l *logger) Code(msg string, code int) {
2759
Code(msg, code)
2860
}
2961

62+
// Codef is a function that logs based on the status code
63+
func (l *logger) Codef(msg string, code int, v ...interface{}) {
64+
Code(fmt.Sprintf(msg, v...), code)
65+
}
66+
3067
// Warn logs a message with the yellow color
3168
func (l *logger) Warn(msg string) {
3269
Warn(msg)
3370
}
71+
72+
// Warnf logs a formatted message with the yellow color
73+
func (l *logger) Warnf(msg string, v ...interface{}) {
74+
Warn(fmt.Sprintf(msg, v...))
75+
}

server/response.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"encoding/json"
5-
"log"
65
"net/http"
76

87
"github.com/opensaucerer/barf/constant"
@@ -11,7 +10,6 @@ import (
1110

1211
// JSON writes a JSON response to the response writer
1312
func JSON(w http.ResponseWriter, status bool, statusCode int, message string, data map[string]interface{}) {
14-
log.Println("JSON", status, statusCode, message, data)
1513
Response(w).Status(statusCode).JSON(typing.Response{
1614
Status: status,
1715
Message: message,

0 commit comments

Comments
 (0)