{"record":{"id":"75c26cb1096dfe10","repo":"dgraph-io/dgraph","slug":"can-t-rename-log-file-s","errorCode":null,"errorMessage":"can't rename log file: %s","messagePattern":"can't rename log file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/log_writer.go","lineNumber":211,"sourceCode":"\t}\n\treturn plainText, nil\n}\n\nfunc (l *LogWriter) rotate() error {\n\tif l == nil {\n\t\treturn nil\n\t}\n\n\tl.flush()\n\tif err := l.file.Close(); err != nil {\n\t\treturn err\n\t}\n\n\tif _, err := os.Stat(l.FilePath); err == nil {\n\t\t// move the existing file\n\t\tnewname := backupName(l.FilePath)\n\t\tif err := os.Rename(l.FilePath, newname); err != nil {\n\t\t\treturn fmt.Errorf(\"can't rename log file: %s\", err)\n\t\t}\n\t}\n\n\tl.manageChannel <- true\n\treturn l.open()\n}\n\nfunc (l *LogWriter) open() error {\n\tif l == nil {\n\t\treturn nil\n\t}\n\n\tif err := os.MkdirAll(filepath.Dir(l.FilePath), 0755); err != nil {\n\t\treturn err\n\t}\n\n\tsize := func() int64 {\n\t\tinfo, err := os.Stat(l.FilePath)","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/log_writer.go#L193-L229","documentation":"Error logged by the log writer (x/log_writer.go) when rotating a log file fails because the rename operation (e.g. moving the current log to a rotated name) returns an error. The file involved is reported via %s. Fix by checking file permissions, locks, and filesystem support for renames in the log directory.","triggerScenarios":"Log rotation triggered via Write when the file exceeds size limits and the OS refuses the rename — e.g. permission problems, the file was replaced/removed concurrently, or cross-device issues.","commonSituations":"External logrotate工具 moving/truncating the file while Dgraph writes, permissions changed after startup, or backup name collisions on the same filesystem.","solutions":["Check process permissions on the log file and its directory","Stop external logrotate jobs from touching the active Dgraph log file","Verify the directory is writable and the file still exists at rotation time","Restart the process to reopen a clean log handle if state is inconsistent"],"exampleFix":"// before: external logrotate touching active file\n/var/log/dgraph/dgraph.log { daily rotate 7 }\n// after: rotate dgraph's own files only, or copytruncate-free exclusion\n/var/log/dgraph/dgraph.log.* { daily rotate 7 missingok }","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(logPath); err != nil { return err }\nif err := syscall.Access(filepath.Dir(logPath), syscall.O_RDWR); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := l.rotate(); err != nil {\n  log.Printf(\"rotation failed, falling back to stderr logging: %v\", err)\n  fallbackToStderr()\n}","preventionTips":["Exclude the active log file from external logrotate jobs","Keep log dir permissions stable for the service user","Avoid NFS for active log files"],"tags":["go","logging","filesystem","log-rotation"],"backgroundTag":"log-file-rename-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}