(config FileConfig)
| 211 | ) |
| 212 | |
| 213 | func createFileWriter(config FileConfig) (io.Writer, error) { |
| 214 | singleFileInit.once.Do(func() { |
| 215 | var logFile io.Writer |
| 216 | fullpath := config.Fullpath() |
| 217 | |
| 218 | // Try to open the existing file |
| 219 | logFile, err := os.OpenFile(fullpath, os.O_APPEND|os.O_WRONLY, filePermMode) |
| 220 | if err != nil { |
| 221 | // If the existing file wasn't found, or couldn't be opened, just ignore |
| 222 | // it and recreate a new one. |
| 223 | logFile, err = createDirFile(config) |
| 224 | // If creating a new logfile fails, then we have no choice but to error out. |
| 225 | if err != nil { |
| 226 | singleFileInit.creationError = err |
| 227 | return |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | singleFileInit.writer = logFile |
| 232 | }) |
| 233 | |
| 234 | return singleFileInit.writer, singleFileInit.creationError |
| 235 | } |
| 236 | |
| 237 | func createDirFile(config FileConfig) (io.Writer, error) { |
| 238 | if config.Dirname != "" { |
no test coverage detected