{"record":{"id":"d2b269aacd68dc31","repo":"slimtoolkit/slim","slug":"failed-to-set-log-output-destination-to-q-touch","errorCode":null,"errorMessage":"failed to set log output destination to %q, touch failed with: %v","messagePattern":"failed to set log output destination to %q, touch failed with: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/logger.go","lineNumber":31,"sourceCode":"\nfunc configureLogger(\n\tenableDebug bool,\n\tlevelName string,\n\tformat string,\n\tlogFile string,\n) error {\n\tif err := setLogLevel(enableDebug, levelName); err != nil {\n\t\treturn fmt.Errorf(\"failed to set log-level: %v\", err)\n\t}\n\n\tif err := setLogFormat(format); err != nil {\n\t\treturn fmt.Errorf(\"failed to set log format: %v\", err)\n\t}\n\n\tif len(logFile) > 0 {\n\t\t// This touch is not ideal - need to understand how to merge this logic with artifacts.PrepareEnv().\n\t\tif err := fsutil.Touch(logFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set log output destination to %q, touch failed with: %v\", logFile, err)\n\t\t}\n\n\t\tf, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set log output destination to %q: %w\", logFile, err)\n\t\t}\n\n\t\tlog.SetOutput(f)\n\t}\n\n\treturn nil\n}\n\nfunc setLogFormat(format string) error {\n\tswitch format {\n\tcase \"text\":\n\t\tlog.SetFormatter(&log.TextFormatter{DisableColors: true})\n\tcase \"json\":","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/logger.go#L13-L49","documentation":"When a log file path is configured, configureLogger first calls fsutil.Touch(logFile) to ensure the file (and its parent directories) exist before opening it for writing. If the touch fails, this error reports that the log output destination could not be prepared.","triggerScenarios":"Configuring Run with a logFile path whose directory cannot be created or written: permission denied, read-only filesystem, invalid path characters, or a non-directory component in the path.","commonSituations":"Log path points inside a read-only container rootfs; log volume not mounted or owned by root while the sensor runs as a non-root user; typo in the log path (e.g. missing directory component).","solutions":["Check the trailing %v cause (fsutil error) and fix the path or its permissions.","Mount a writable volume for the log file and ensure the sensor user can create files there.","Run without a log file (stdout logging) if persistent file logging is not required."],"exampleFix":"// before\n--log-file /var/log/sensor.log   # /var/log is read-only\n// after\n--log-file /var/log/sensor/sensor.log  # with writable volume mounted at /var/log/sensor","handlingStrategy":"validation","validationCode":"func ensureLogFile(path string) error {\n    if path == \"\" { return nil }\n    dir := filepath.Dir(path)\n    if err := os.MkdirAll(dir, 0755); err != nil { return err }\n    return os.WriteFile(path, nil, 0644) // noop if exists\n}","typeGuard":"func isTouchFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"touch failed with\")\n}","tryCatchPattern":"if err := Run(ctx); err != nil && strings.Contains(err.Error(), \"touch failed with\") {\n    fmt.Fprintf(os.Stderr, \"log path unwritable: %v\\n\", err)\n    os.Exit(1)\n}","preventionTips":["Mount a writable volume for log files instead of writing to the read-only rootfs.","Create the log directory with os.MkdirAll in the entrypoint before starting the sensor.","Grant the sensor user write access to the log directory.","If file logging is optional, omit --log-file to use stdout."],"tags":["logging","filesystem","permissions","configuration"],"backgroundTag":"file-permission-denied","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}