slimtoolkit/slim · error
failed to set log output destination to %q, touch failed wit
Error message
failed to set log output destination to %q, touch failed with: %v
What it means
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.
Source
Thrown at pkg/app/sensor/logger.go:31
func configureLogger(
enableDebug bool,
levelName string,
format string,
logFile string,
) error {
if err := setLogLevel(enableDebug, levelName); err != nil {
return fmt.Errorf("failed to set log-level: %v", err)
}
if err := setLogFormat(format); err != nil {
return fmt.Errorf("failed to set log format: %v", err)
}
if len(logFile) > 0 {
// This touch is not ideal - need to understand how to merge this logic with artifacts.PrepareEnv().
if err := fsutil.Touch(logFile); err != nil {
return fmt.Errorf("failed to set log output destination to %q, touch failed with: %v", logFile, err)
}
f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
return fmt.Errorf("failed to set log output destination to %q: %w", logFile, err)
}
log.SetOutput(f)
}
return nil
}
func setLogFormat(format string) error {
switch format {
case "text":
log.SetFormatter(&log.TextFormatter{DisableColors: true})
case "json":View on GitHub (pinned to 81940d17fa)
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.
Example fix
// before --log-file /var/log/sensor.log # /var/log is read-only // after --log-file /var/log/sensor/sensor.log # with writable volume mounted at /var/log/sensor
Defensive patterns
Strategy: validation
Validate before calling
func ensureLogFile(path string) error {
if path == "" { return nil }
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0755); err != nil { return err }
return os.WriteFile(path, nil, 0644) // noop if exists
} Type guard
func isTouchFailure(err error) bool {
return err != nil && strings.Contains(err.Error(), "touch failed with")
} Try / catch
if err := Run(ctx); err != nil && strings.Contains(err.Error(), "touch failed with") {
fmt.Fprintf(os.Stderr, "log path unwritable: %v\n", err)
os.Exit(1)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- failed to set log output destination to %q: %w
- cannot open file %q to duplicate app's %s stream: %w
- cannot create execution - touch event file %q failed: %w
- cannot create execution - open event file %q failed: %w
- cannot create execution - cannot read command file %q: %w
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/d2b269aacd68dc31.
Report an issue: GitHub.