MCPcopy
hub / github.com/cloudflare/cloudflared / createFileWriter

Function createFileWriter

logger/create.go:213–235  ·  view source on GitHub ↗
(config FileConfig)

Source from the content-addressed store, hash-verified

211)
212
213func 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
237func createDirFile(config FileConfig) (io.Writer, error) {
238 if config.Dirname != "" {

Callers 1

newZerologFunction · 0.85

Calls 3

createDirFileFunction · 0.85
FullpathMethod · 0.80
DoMethod · 0.45

Tested by

no test coverage detected