Repository: traefik/traefik (language: go)

Issue:
Log files not persisted on container restart
### Welcome!

- [X] Yes, I've searched similar issues on [GitHub](https://github.com/traefik/traefik/issues) and didn't find any.
- [X] Yes, I've searched similar issues on the [Traefik community forum](https://community.traefik.io) and didn't find any.

### What did you do?

The defined log files (traefik.log and access.log) on the host are wiped and start afresh when the container is restarted. This behaviour seems to be specific to v3 as it does not seem to be present on v2 with the same configuration.

### What did you see instead?

Logs should remain if the container restarts - file should be appended.

### What version of Traefik are you using?

Version:      3.0.0
Codename:     beaufort
Go version:   go1.22.2
Built:        2024-04-29T14:25:59Z
OS/Arch:      linux/amd64

### What is your environment & configuration?

```yaml
  traefik:
    container_name: "traefik"
    image: "traefik:latest"
    restart: "unless-stopped"
    depends_on:
      - cetusguard
    networks:
      - "cetusguard"
      - "traefik"
    healthcheck:
    # Run traefik healthcheck command
    # https://doc.traefik.io/traefik/operations/cli/#healthcheck
      test: ["CMD", "traefik", "healthcheck", "--ping"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 5s
    ports:
      # To be able to listen on port 80 (http)
      - mode: host
        published: 80
        target: 80
        protocol: tcp
      # To be able to listen on port 443 (https)
      - mode: host
        published: 443
        target: 443
        protocol: tcp
      # To enable HTTP/3 (QUIC)
      - mode: host
        published: 443
        target: 443
        protocol: udp
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    secrets:
      - do_auth_token
    environment:
      - DO_AUTH_TOKEN_FILE=/run/secrets/do_auth_token
    volumes:
      - type: bind
        source: /etc/localtime
        target: /etc/localtime
        read_only: true
      - type: bind                                                    # Location of data folder
        source: /etc/traefik/data
        target: /data
      - type: bind
        source: /var/log/traefik
        target: /var/log/traefik
      - type: bind                                                    # Location to write certificates to
        source: /etc/traefik/acme/acme.json
        target: /acme.json
      - type: bind
        source: /etc/traefik/traefik.yml                              # Static Traefik Configuration
        target: /etc/traefik/traefik.yml
        read_only: true
      - type: bind
        source: /etc/traefik/conf.d
        target: /etc/traefik/conf.d
        read_only: true
```

traefik.yml

```yaml
log:
  filePath: "/var/log/traefik/traefik.log"
  level: DEBUG
  maxBackups: 5

accessLog:
  filePath: "/var/log/traefik/access.log"
  bufferingSize: 20
  filters:
    statusCodes:
      - "204-299"
      - "400-499"
      - "500-599"
    retryAttempts: true
```


### If applicable, please paste the log output in DEBUG level

_No response_


Discussion / hints:

Fix patch:
diff --git a/cmd/traefik/logger.go b/cmd/traefik/logger.go
index 4a3a10893a..58b7abbe3d 100644
--- a/cmd/traefik/logger.go
+++ b/cmd/traefik/logger.go
@@ -49,7 +49,7 @@ func getLogWriter(staticConfiguration *static.Configuration) io.Writer {
 	var w io.Writer = os.Stderr
 
 	if staticConfiguration.Log != nil && len(staticConfiguration.Log.FilePath) > 0 {
-		_, _ = os.Create(staticConfiguration.Log.FilePath)
+		_, _ = os.OpenFile(staticConfiguration.Log.FilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666)
 		w = &lumberjack.Logger{
 			Filename:   staticConfiguration.Log.FilePath,
 			MaxSize:    staticConfiguration.Log.MaxSize,


Test patch: