feat(cmd/joj3): ndjson debug log
This commit is contained in:
		
							parent
							
								
									6f013058a9
								
							
						
					
					
						commit
						cd9174d7c7
					
				|  | @ -62,16 +62,24 @@ func (h *multiHandler) WithGroup(name string) slog.Handler { | ||||||
| func setupSlog(logPath string) error { | func setupSlog(logPath string) error { | ||||||
| 	handlers := []slog.Handler{} | 	handlers := []slog.Handler{} | ||||||
| 	if logPath != "" { | 	if logPath != "" { | ||||||
| 		// File handler for debug logs
 | 		// Text file handler for debug logs
 | ||||||
| 		debugFile, err := os.OpenFile(logPath, | 		debugTextFile, err := os.OpenFile(logPath, | ||||||
| 			os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640) | 			os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		debugFileHandler := slog.NewTextHandler(debugFile, &slog.HandlerOptions{ | 		debugTextHandler := slog.NewTextHandler(debugTextFile, | ||||||
| 			Level: slog.LevelDebug, | 			&slog.HandlerOptions{Level: slog.LevelDebug}) | ||||||
| 		}) | 		handlers = append(handlers, debugTextHandler) | ||||||
| 		handlers = append(handlers, debugFileHandler) | 		// Json file handler for debug logs
 | ||||||
|  | 		debugJsonFile, err := os.OpenFile(logPath+".ndjson", | ||||||
|  | 			os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 		debugJsonHandler := slog.NewJSONHandler(debugJsonFile, | ||||||
|  | 			&slog.HandlerOptions{Level: slog.LevelDebug}) | ||||||
|  | 		handlers = append(handlers, debugJsonHandler) | ||||||
| 	} | 	} | ||||||
| 	stderrLogLevel := slog.LevelInfo | 	stderrLogLevel := slog.LevelInfo | ||||||
| 	if runningTest { | 	if runningTest { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user