rogerc / file-stream-rotator

NodeJS file stream rotator
MIT License
143 stars 69 forks source link

Setting symlinkName with a variable that includes a '.' doesn't create the symlink #86

Closed chan4est closed 2 years ago

chan4est commented 2 years ago
>> node --version
v14.17.6
>> npm --version
7.24.1

>> sw_vers
ProductName:    macOS
ProductVersion: 11.6.2
BuildVersion:   20G314

"file-stream-rotator": "^0.5.7"

Creates symlink properly

new transports.DailyRotateFile({
    filename: `${filePath}-%DATE%.log`,
    datePattern: 'YYYY-MM-DD',
    zippedArchive: true,
    maxFiles: '14d',
    createSymlink: true,
    symlinkName: 'test.log',
});

Fails to create a symlink. Just a regular file with the symlinkName is created

const symlinkFileName = 'test.log';
new transports.DailyRotateFile({
    filename: `${filePath}-%DATE%.log`,
    datePattern: 'YYYY-MM-DD',
    zippedArchive: true,
    maxFiles: '14d',
    createSymlink: true,
    symlinkName: symlinkFileName
});
rogerc commented 2 years ago

Just tested it and seems to work fine using the test.

Output below.

lrwxr-xr-x  1 user  wheel      28 19 Jan 22:36 tail.log -> testlog-2022-01-19.22.36.log
-rw-r--r--  1 user  wheel  282952 19 Jan 22:36 testlog-2022-01-19.22.36.log

The test setup is below.

const symLinkName = 'tail.log'

var rotatingLogStream = require('../FileStreamRotator').getStream({
    filename: "logs/1m/testlog-%DATE%", 
    frequency: "1m", 
    verbose: true, 
    date_format: "YYYY-MM-DD.HH.mm", 
    size: "500k", 
    max_logs: "10",
    audit_file: "/tmp/audit.json",
    end_stream: false,
    utc: true,
    extension: ".log",
    create_symlink: true,
    symlink_name: symLinkName
});