(p []byte)
| 89 | } |
| 90 | |
| 91 | func (lb *LogBuffer) Write(p []byte) (n int, err error) { |
| 92 | lb.mu.Lock() |
| 93 | |
| 94 | content := string(p) |
| 95 | |
| 96 | if lb.UsePTY { |
| 97 | content = stripControlSequences(content) |
| 98 | } |
| 99 | |
| 100 | content = strings.ReplaceAll(content, "\r\n", "\n") |
| 101 | |
| 102 | if !strings.Contains(content, "\n") && strings.Contains(content, "\r") { |
| 103 | parts := strings.Split(content, "\r") |
| 104 | content = parts[len(parts)-1] |
| 105 | } else { |
| 106 | content = strings.ReplaceAll(content, "\r", "\n") |
| 107 | } |
| 108 | |
| 109 | lines := strings.Split(content, "\n") |
| 110 | |
| 111 | var toSend []string |
| 112 | |
| 113 | for _, line := range lines { |
| 114 | line = strings.TrimSpace(line) |
| 115 | if line == "" || line == "\\" || line == "\\\\" { |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | trimmed := strings.Trim(line, "\\") |
| 120 | if trimmed == "" { |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | if len(lb.Lines) >= lb.MaxLines { |
| 125 | lb.Lines = lb.Lines[1:] |
| 126 | } |
| 127 | |
| 128 | lb.Lines = append(lb.Lines, line) |
| 129 | toSend = append(toSend, line) |
| 130 | } |
| 131 | |
| 132 | serviceName := lb.ServiceName |
| 133 | lb.mu.Unlock() |
| 134 | |
| 135 | for _, line := range toSend { |
| 136 | NewServiceLog(serviceName, line) |
| 137 | } |
| 138 | |
| 139 | return len(p), nil |
| 140 | } |
| 141 | |
| 142 | func NewServiceLog(serviceName string, logStr string) { |
| 143 | newLog, err := json.Marshal(fiber.Map{ |
no test coverage detected