Skip to content

FileLoggingHandler fails the first time it creates a log file #1877

@Plastonick

Description

@Plastonick

Describe the bug

When FileLoggingHandler first tries to create the log file, it necessarily fails since symfony/filesystem's touch method returns void, whereas FileLoggingHandler uses it as though it returns boolean.

See:

$file = new File($this->logFile, false);
// Suppress E_WARNING if not exists
if (@$this->fileSystem->exists($this->logFile)) {
    if (!$file->isWritable()) {
        throw new CannotWriteFileException(
            sprintf("Could not write to logfile: %s", $this->logFile),
        );
    }

 // this is necessarily true, since `touch` returns void. `touch` throws an exception on failure.
} elseif (!$this->fileSystem->touch($this->logFile)) {
    throw new CannotWriteFileException(sprintf(
        "The logging directory is not writable for the web server user. Could not create logfile: %s",
        $this->logFile,
    ));
}

To Reproduce

  1. Turn on filesystem logging in the configuration
  2. pointing the logger at a file that doesn't yet exist
  3. prompt it to log something, note it creates the log file, but then immediately throws an exception
  4. subsequent attempts will succeed, since the file will exist

Expected behavior

it should not fail by default if the log file doesn't yet exist.

Screenshots or logs

n/a

Additional context

I believe simplesamlphp used to use PHP's touch method previously, which does have a boolean return indicating success.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions