Logback does not recreate log file after file has been deleted

While your application is running (and Logback within your application has an open handle to the log file) if you delete the log file then Logback won't know that the the file has been deleted (since the Logback process still has an open file handle) but since the file has been deleted Logback cannot actually write anything to disk and this situation remains until Logback is re-initialised (and your FileAppender recreates the file). Typically, this will be done on application startup.

There's an open issue against Logback requesting a change in Logback's behaviour in this situation.

It is somewhat unusual to delete a file which an application's logging sub system (i.e Logback) is configured to write to while that application is active. Perhaps the issue you are trying to address by deleting the file could be addressed in some other way? If not i.e. if you must be able to delete an in-flight log file and expect Logback to create a new file then I think your options are:

  • Vote for issue and hope it is resolved soon
  • Contribute a PR with a fix for that issue
  • Fork Logback and create your own patched version

The accepted answer above is perfectly correct - if you anyways have to "delete" a logfile for some reason another option would be recreating it yourself or just "truncating" it instead of deleting:

$truncate -s0 /var/log/audit/audit.log

# or if your shell does not support `truncate` (like mine on mac) try redirecting no content to your logfile:
$ :> /var/log/audit/audit.log

At least that was perfectly ok in my situation and logback just continued logging...