@@ -44,13 +44,13 @@ func main() {
4444 gocolorlog.Info (" Starting application" )
4545 gocolorlog.Infof (" Listening on port %d " , 8080 )
4646 gocolorlog.Warn (" Cache miss for key user:123" )
47- gocolorlog.Warnf (" Slow query: %s " , " SELECT * FROM users" )
47+ gocolorlog.Warnf (" Slow query: %s " , " SELECT * FROM users" )
4848 gocolorlog.Error (" Failed to connect to DB" )
4949 gocolorlog.Errorf (" Failed to open file: %s " , " config.yaml" )
5050
51- gocolorlog.HTTP (200 , " GET" , " /api/test" , 120 *time.Millisecond ," ip-adress" , nil )
52- gocolorlog.HTTP (404 , " POST" , " /api/notfound" , 80 *time.Millisecond ," ip-adress" , nil )
53- gocolorlog.HTTP (500 , " DELETE" , " /api/error" , 200 *time.Millisecond ," ip-adress" , fmt.Errorf (" internal server error" ))
51+ gocolorlog.HTTP (200 , " GET" , " /api/test" , 120 *time.Millisecond ," ip-adress" , " " , nil )
52+ gocolorlog.HTTP (404 , " POST" , " /api/notfound" , 80 *time.Millisecond ," ip-adress" ," Requsetid " , nil )
53+ gocolorlog.HTTP (500 , " DELETE" , " /api/error" , 200 *time.Millisecond ," ip-adress" , " Requsetid " , fmt.Errorf (" internal server error" ))
5454
5555 gocolorlog.ContextLevel (" INFO" , " Bootstrap" , " Application is running on: %s " , " http://localhost:3000" )
5656}
@@ -65,8 +65,8 @@ func main() {
6565[Log] 12345 - 2025-05-15 12:34:56 [ERROR] [App] Failed to connect to DB
6666[Log] 12345 - 2025-05-15 12:34:56 [ERROR] [App] Failed to open file: config.yaml
6767[Log] 62388 - 2025-05-16 21:29:01 HTTP [200] GET | /api/test | 200 | 120ms - 120ms | 192.168.1.1
68- [Log] 62388 - 2025-05-16 21:29:01 HTTP [404] POST | /api/notfound | 404 | 80ms - 80ms | 192.168.1.1 |
69- [Log] 62388 - 2025-05-16 21:29:01 HTTP [500] DELETE | /api/error | 500 | 200ms - 200ms | 192.168.1.1 | [Error]: internal server error
68+ [Log] 62388 - 2025-05-16 21:29:01 HTTP [404] POST | /api/notfound | 404 | 80ms - 80ms | RequestID: 71g261g61 | 192.168.1.1 |
69+ [Log] 62388 - 2025-05-16 21:29:01 HTTP [500] DELETE | /api/error | 500 | 200ms - 200ms | 192.168.1.1 | RequestID: 71g261g61 | [Error]: internal server error
7070[Log] 12345 - 2025-05-15 12:34:56 [INFO ] [Bootstrap] Application is running on: http://localhost:3000
7171```
7272* (Colors will be visible in a terminal that supports ANSI colors.)*
@@ -85,7 +85,7 @@ type Logger interface {
8585 Warnf (format string , args ...any )
8686 Error (msg string )
8787 Errorf (format string , args ...any )
88- HTTP (status int , method, path string , latency time.Duration , ip string , err error )
88+ HTTP (status int , method, path string , latency time.Duration , ip string , requestID string , err error )
8989 ContextLevel (level, context, msg string , args ...any )
9090}
9191```
@@ -105,7 +105,7 @@ type Logger interface {
105105``` go
106106gocolorlog.Info (" Message" )
107107gocolorlog.Warnf (" Warning: %s " , " details" )
108- gocolorlog.HTTP (404 , " POST" , " /api/notfound" , 80 *time.Millisecond ," ip-adress" nil )
108+ gocolorlog.HTTP (404 , " POST" , " /api/notfound" , 80 *time.Millisecond ," ip-adress" , " " , nil )
109109gocolorlog.ContextLevel (" ERROR" , " DB" , " Connection error: %v " , err)
110110```
111111
0 commit comments