FileWriter can write logs to files. By default, log files are rotated ("rolled") when they get large, and old log files get deleted, to ensure that the process does not exhaust disk space.
| 83 | // files get deleted, to ensure that the process does not |
| 84 | // exhaust disk space. |
| 85 | type FileWriter struct { |
| 86 | // Filename is the name of the file to write. |
| 87 | Filename string `json:"filename,omitempty"` |
| 88 | |
| 89 | // The file permissions mode. |
| 90 | // 0600 by default. |
| 91 | Mode fileMode `json:"mode,omitempty"` |
| 92 | |
| 93 | // DirMode controls permissions for any directories created to reach Filename. |
| 94 | // Default: 0700 (current behavior). |
| 95 | // |
| 96 | // Special values: |
| 97 | // - "inherit" → copy the nearest existing parent directory's perms (with r→x normalization) |
| 98 | // - "from_file" → derive from the file Mode (with r→x), e.g. 0644 → 0755, 0600 → 0700 |
| 99 | // Numeric octal strings (e.g. "0755") are also accepted. Subject to process umask. |
| 100 | DirMode string `json:"dir_mode,omitempty"` |
| 101 | |
| 102 | // Roll toggles log rolling or rotation, which is |
| 103 | // enabled by default. |
| 104 | Roll *bool `json:"roll,omitempty"` |
| 105 | |
| 106 | // When a log file reaches approximately this size, |
| 107 | // it will be rotated. |
| 108 | RollSizeMB int `json:"roll_size_mb,omitempty"` |
| 109 | |
| 110 | // Roll log file after some time |
| 111 | RollInterval time.Duration `json:"roll_interval,omitempty"` |
| 112 | |
| 113 | // Roll log file at fix minutes |
| 114 | // For example []int{0, 30} will roll file at xx:00 and xx:30 each hour |
| 115 | // Invalid value are ignored with a warning on stderr |
| 116 | // See https://github.com/DeRuina/timberjack#%EF%B8%8F-rotation-notes--warnings for caveats |
| 117 | RollAtMinutes []int `json:"roll_minutes,omitempty"` |
| 118 | |
| 119 | // Roll log file at fix time |
| 120 | // For example []string{"00:00", "12:00"} will roll file at 00:00 and 12:00 each day |
| 121 | // Invalid value are ignored with a warning on stderr |
| 122 | // See https://github.com/DeRuina/timberjack#%EF%B8%8F-rotation-notes--warnings for caveats |
| 123 | RollAt []string `json:"roll_at,omitempty"` |
| 124 | |
| 125 | // Whether to compress rolled files. |
| 126 | // Default: true. |
| 127 | // Deprecated: Use RollCompression instead, setting it to "none". |
| 128 | RollCompress *bool `json:"roll_gzip,omitempty"` |
| 129 | |
| 130 | // RollCompression selects the compression algorithm for rolled files. |
| 131 | // Accepted values: "none", "gzip", "zstd". |
| 132 | // Default: gzip |
| 133 | RollCompression string `json:"roll_compression,omitempty"` |
| 134 | |
| 135 | // Whether to use local timestamps in rolled filenames. |
| 136 | // Default: false |
| 137 | RollLocalTime bool `json:"roll_local_time,omitempty"` |
| 138 | |
| 139 | // The maximum number of rolled log files to keep. |
| 140 | // Default: 10 |
| 141 | RollKeep int `json:"roll_keep,omitempty"` |
| 142 |
nothing calls this directly
no outgoing calls
no test coverage detected