@@ -10,7 +10,7 @@ import (
1010 "github.com/armbian/ansi-hastebin/internal/keygenerator"
1111 "github.com/armbian/ansi-hastebin/internal/storage"
1212 "github.com/go-chi/chi/v5"
13- "github.com/sirupsen/logrus "
13+ "github.com/rs/zerolog/log "
1414)
1515
1616// DocumentHandler manages document operations
@@ -50,34 +50,34 @@ func (h *DocumentHandler) HandleGet(w http.ResponseWriter, r *http.Request) {
5050 data , err := h .Store .Get (key , false )
5151
5252 if data != "" && err == nil {
53- logrus . WithField ( "key" , key ).Info ("Retrieved document" )
53+ log . Info (). Str ( "key" , key ).Msg ("Retrieved document" )
5454 w .Header ().Set ("Content-Type" , "application/json" )
5555 if r .Method == http .MethodHead {
5656 w .WriteHeader (http .StatusOK )
5757 return
5858 }
5959 json .NewEncoder (w ).Encode (map [string ]string {"data" : data , "key" : key })
6060 } else {
61- logrus . WithField ( "key" , key ).Warn ("Document not found" )
61+ log . Info (). Str ( "key" , key ).Msg ("Document not found" )
6262 http .Error (w , `{"message": "Document not found."}` , http .StatusNotFound )
6363 }
6464}
6565
6666// Handle retrieving raw document
6767func (h * DocumentHandler ) HandleRawGet (w http.ResponseWriter , r * http.Request ) {
68-
6968 key := strings .Split (chi .URLParam (r , "id" ), "." )[0 ]
7069 data , err := h .Store .Get (key , false )
70+
7171 if data != "" && err == nil {
72- logrus . WithField ( "key" , key ).Info ("Retrieved raw document" )
72+ log . Info (). Str ( "key" , key ).Msg ("Retrieved raw document" )
7373 w .Header ().Set ("Content-Type" , "text/plain; charset=UTF-8" )
7474 if r .Method == http .MethodHead {
7575 w .WriteHeader (http .StatusOK )
7676 return
7777 }
7878 w .Write ([]byte (data ))
7979 } else {
80- logrus . WithField ( "key" , key ).Warn ("Raw document not found" )
80+ log . Info (). Str ( "key" , key ).Msg ("Raw document not found" )
8181 http .Error (w , `{"message": "Document not found."}` , http .StatusNotFound )
8282 }
8383}
@@ -91,15 +91,15 @@ func (h *DocumentHandler) HandlePost(w http.ResponseWriter, r *http.Request) {
9191 }
9292
9393 if h .MaxLength > 0 && buffer .Len () > h .MaxLength {
94- logrus . Warn ("Document exceeds max length" )
94+ log . Info (). Str ( "key" , "" ). Msg ("Document exceeds max length" )
9595 http .Error (w , `{"message": "Document exceeds maximum length."}` , http .StatusBadRequest )
9696 return
9797 }
9898
9999 key := h .KeyGenerator .Generate (h .KeyLength )
100100 h .Store .Set (key , buffer .String (), false )
101101
102- logrus . WithField ( "key" , key ).Info ("Added document" )
102+ log . Info (). Str ( "key" , key ).Msg ("Added document" )
103103 w .Header ().Set ("Content-Type" , "application/json" )
104104 json .NewEncoder (w ).Encode (map [string ]string {"key" : key })
105105}
@@ -113,15 +113,15 @@ func (h *DocumentHandler) HandlePutLog(w http.ResponseWriter, r *http.Request) {
113113 }
114114
115115 if h .MaxLength > 0 && buffer .Len () > h .MaxLength {
116- logrus . Warn ("Document exceeds max length" )
116+ log . Info (). Str ( "key" , "" ). Msg ("Document exceeds max length" )
117117 http .Error (w , `{"message": "Document exceeds maximum length."}` , http .StatusBadRequest )
118118 return
119119 }
120120
121121 key := h .KeyGenerator .Generate (h .KeyLength )
122122 h .Store .Set (key , buffer .String (), false )
123123
124- logrus . WithField ( "key" , key ).Info ("Added document with log link" )
124+ log . Info (). Str ( "key" , key ).Msg ("Added document with log link" )
125125 w .Header ().Set ("Content-Type" , "text/plain" )
126126 fmt .Fprintf (w , "\n https://%s/%s\n \n " , r .Host , key )
127127}
@@ -136,7 +136,7 @@ func (h *DocumentHandler) readBody(r *http.Request, buffer *strings.Builder) err
136136 } else {
137137 data , err := io .ReadAll (r .Body )
138138 if err != nil {
139- logrus .Error ("Connection error: " , err )
139+ log .Error (). Err ( err ). Msg ( "Error reading request body" )
140140 return err
141141 }
142142 buffer .WriteString (string (data ))
0 commit comments