| 1874 | } |
| 1875 | |
| 1876 | func LogStackTraces(ctx context.Context, logDirectory string, stackTrace bytes.Buffer, timestamp string) { |
| 1877 | |
| 1878 | // log to console |
| 1879 | _, _ = fmt.Fprintf(os.Stderr, "Stack trace:\n%s\n", stackTrace.String()) |
| 1880 | |
| 1881 | err := writeStackTraceFile(ctx, logDirectory, timestamp, stackTrace) |
| 1882 | if err != nil { |
| 1883 | return |
| 1884 | } |
| 1885 | |
| 1886 | rotatePath := filepath.Join(logDirectory, StackFilePrefix+"*.log") |
| 1887 | err = RotateFilenamesIfNeeded(rotatePath) |
| 1888 | if err != nil { |
| 1889 | WarnfCtx(ctx, "Error rotating stack trace files in path %s: %v", rotatePath, err) |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | func writeStackTraceFile(ctx context.Context, logDirectory, timestamp string, stackTrace bytes.Buffer) error { |
| 1894 | filename := filepath.Join(logDirectory, StackFilePrefix+timestamp+".log") |