Skip to content

tracing-appender has broken symlinks when a relative path is specified #3599

Description

@Sculas

Bug Report

Version

│   ├── tracing v0.1.44
│   │   ├── tracing-attributes v0.1.31 (proc-macro)
│   │   └── tracing-core v0.1.36
│   ├── tracing-appender v0.2.5
│   │   └── tracing-subscriber v0.3.23
│   │       ├── tracing-core v0.1.36 (*)
│   │       └── tracing-log v0.2.0
│   │           └── tracing-core v0.1.36 (*)
│   └── tracing-subscriber v0.3.23 (*)
└── tracing v0.1.44 (*)

Platform

Linux 7.1.8-1-cachyos SMP PREEMPT_DYNAMIC x86_64 GNU/Linux

Crates

tracing-appender v0.2.5

Description

When using the latest_symlink feature added in #3447, if a relative path is specified to Builder::build, the symlink also uses the relative path. This results in broken symlinks when a relative path to a directory is specified.

For example, this code:

let appender = RollingFileAppender::builder()
    .rotation(Rotation::DAILY)
    .filename_prefix("myapp.log")
    .latest_symlink("latest.log")
    .build("./logs")
    .expect("failed to initialize rolling file appender");

Results in the symlink latest.log to point to ./logs/myapp.log.2019-01-01 while itself already inside of the logs directory, so it actually points to ./logs/./logs/myapp.log.2019-01-01, which is invalid.

The workaround is to always specify an absolute path to Builder::build. But this should be fixed by providing the correct path to symlink::symlink_file (either absolute, or fixing the relative path so it's correct):

if let Some(symlink_name) = latest_symlink_name {
let symlink_path = directory.join(symlink_name);
let _ = symlink::remove_symlink_file(&symlink_path);
symlink::symlink_file(path, symlink_path).map_err(InitError::ctx(
"failed to create symlink to latest log file",
))?;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions