Skip to content
Snippets Groups Projects
Commit 18905b29 authored by Neil-Jocelyn Schark's avatar Neil-Jocelyn Schark
Browse files

improve logging

parent 516e5707
No related branches found
No related tags found
1 merge request!215Simple longevity tests
Pipeline #224092 passed
This commit is part of merge request !215. Comments created here will be created in the context of that merge request.
...@@ -14,6 +14,7 @@ RUN --mount=type=cache,target=/root/go/pkg/mod \ ...@@ -14,6 +14,7 @@ RUN --mount=type=cache,target=/root/go/pkg/mod \
FROM ${GITLAB_PROXY}debian:12-slim AS debian FROM ${GITLAB_PROXY}debian:12-slim AS debian
RUN apt-get update && apt-get upgrade -y RUN apt-get update && apt-get upgrade -y
COPY --from=builder app/artifacts/akms-simulator /usr/bin/akms-simulator COPY --from=builder app/artifacts/akms-simulator /usr/bin/akms-simulator
RUN mkdir /logs
EXPOSE 4444 EXPOSE 4444
ENTRYPOINT ["/usr/bin/akms-simulator"] ENTRYPOINT ["/usr/bin/akms-simulator"]
...@@ -12,6 +12,11 @@ import ( ...@@ -12,6 +12,11 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
const (
// LogFile is the file where the log is stored.
LogFilePath = "/logs/akms-simulator.log"
)
type LogFile struct { type LogFile struct {
Source string `json:"source"` Source string `json:"source"`
Body PushKSAKeyRequest `json:"body"` Body PushKSAKeyRequest `json:"body"`
...@@ -79,7 +84,7 @@ func main() { ...@@ -79,7 +84,7 @@ func main() {
func getLogFile(w http.ResponseWriter, r *http.Request) { func getLogFile(w http.ResponseWriter, r *http.Request) {
logrus.Info("Log file requested") logrus.Info("Log file requested")
http.ServeFile(w, r, "akms-simulator.log") http.ServeFile(w, r, LogFilePath)
} }
func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { func handlePushKsaKey(w http.ResponseWriter, r *http.Request) {
...@@ -116,7 +121,7 @@ func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { ...@@ -116,7 +121,7 @@ func handlePushKsaKey(w http.ResponseWriter, r *http.Request) {
} }
// Append jsonLogFile to akms-logfile.log // Append jsonLogFile to akms-logfile.log
f, err := os.OpenFile("akms-simulator.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) f, err := os.OpenFile(LogFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil { if err != nil {
logrus.Errorf("Error opening log file: %s", err) logrus.Errorf("Error opening log file: %s", err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
...@@ -128,6 +133,12 @@ func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { ...@@ -128,6 +133,12 @@ func handlePushKsaKey(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
// Write the newline character
if _, err := f.Write([]byte("\n")); err != nil {
logrus.Errorf("Error writing newline to log file: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment