@@ -63,18 +63,12 @@ func LogsHandler(routerAPIURL string) http.HandlerFunc {
6363 if runningInContainer {
6464 // Running inside container - use supervisorctl to get logs
6565 response .DeploymentType = "docker"
66- logs , err := fetchContainerLogs (component , lines )
66+ logs , err := responseLogs (component , lines )
67+
6768 if err != nil {
6869 response .Error = err .Error ()
6970 } else {
70- for _ , line := range logs {
71- if line != "" {
72- response .Logs = append (response .Logs , LogEntry {
73- Line : line ,
74- Service : component ,
75- })
76- }
77- }
71+ response .Logs = logs
7872 }
7973 } else {
8074 // Running outside container - check Docker container status
@@ -83,18 +77,12 @@ func LogsHandler(routerAPIURL string) http.HandlerFunc {
8377 switch containerStatus {
8478 case "running" , "exited" :
8579 response .DeploymentType = "docker"
86- logs , err := fetchContainerLogs (component , lines )
80+ logs , err := responseLogs (component , lines )
81+
8782 if err != nil {
8883 response .Error = err .Error ()
8984 } else {
90- for _ , line := range logs {
91- if line != "" {
92- response .Logs = append (response .Logs , LogEntry {
93- Line : line ,
94- Service : component ,
95- })
96- }
97- }
85+ response .Logs = logs
9886 }
9987
10088 case "not found" :
@@ -277,3 +265,25 @@ func splitLogLines(output string) []string {
277265 }
278266 return result
279267}
268+
269+ // responseLogs returns logs for a component
270+ func responseLogs (component string , lines int ) ([]LogEntry , error ) {
271+ logs , err := fetchContainerLogs (component , lines )
272+ logEntries := []LogEntry {}
273+
274+ if err != nil {
275+ return nil , err
276+ }
277+
278+ for _ , line := range logs {
279+ if line == "" {
280+ continue
281+ }
282+ logEntries = append (logEntries , LogEntry {
283+ Line : line ,
284+ Service : component ,
285+ })
286+ }
287+
288+ return logEntries , nil
289+ }
0 commit comments