Comparing version 1.0.0 to 1.0.1
@@ -87,2 +87,11 @@ 'use strict' | ||
async function getFileSize (filePath) { | ||
try { | ||
const fileStats = await stat(filePath) | ||
return fileStats.size | ||
} catch { | ||
return 0 | ||
} | ||
} | ||
async function detectLastNumber (fileVal, time = null) { | ||
@@ -138,3 +147,4 @@ const fileName = getFileName(fileVal) | ||
getFileName, | ||
getFileSize, | ||
validateLimitOptions | ||
} |
{ | ||
"name": "pino-roll", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A Pino transport that automatically rolls your log files", | ||
@@ -5,0 +5,0 @@ "main": "pino-roll.js", |
@@ -11,2 +11,3 @@ 'use strict' | ||
getNext, | ||
getFileSize, | ||
validateLimitOptions | ||
@@ -80,3 +81,3 @@ } = require('./lib/utils') | ||
const createdFileNames = [fileName] | ||
let currentSize = 0 | ||
let currentSize = await getFileSize(fileName) | ||
const maxSize = parseSize(size) | ||
@@ -99,3 +100,3 @@ | ||
currentSize = 0 | ||
// delay to let the our destination finish its write | ||
// delay to let the destination finish its write | ||
setTimeout(roll, 0) | ||
@@ -102,0 +103,0 @@ } |
@@ -10,2 +10,3 @@ 'use strict' | ||
buildFileName, | ||
getFileSize, | ||
detectLastNumber, | ||
@@ -57,3 +58,3 @@ getNext, | ||
test('getNext()', async ({ same, throws }) => { | ||
test('getNext()', async ({ same }) => { | ||
const today = new Date() | ||
@@ -82,2 +83,19 @@ | ||
test('getFileSize()', async ({ test, beforeEach }) => { | ||
const folder = join('logs', 'utils') | ||
beforeEach(() => cleanAndCreateFolder(folder)) | ||
test('given an existing file', async ({ equal }) => { | ||
const fileName = join(folder, 'file.log') | ||
await writeFile(fileName, '123') | ||
equal(await getFileSize(fileName), 3, 'detects size of existing file') | ||
}) | ||
test('given a non existing file', async ({ equal }) => { | ||
const fileName = join(folder, 'file.log') | ||
equal(await getFileSize(fileName), 0, 'set current size to 0 with non existing file') | ||
}) | ||
}) | ||
test('detectLastNumber()', async ({ test, beforeEach }) => { | ||
@@ -84,0 +102,0 @@ const folder = join('logs', 'utils') |
@@ -126,3 +126,3 @@ 'use strict' | ||
}) | ||
for (let i = 1; i <= 7; i++) { | ||
for (let i = 1; i <= 6; i++) { | ||
stream.write(`logged message #${i}\n`) | ||
@@ -138,10 +138,9 @@ await sleep(20) | ||
ok(content.includes('#3'), 'second file contains third log') | ||
ok(content.includes('#4'), 'second file contains fourth log') | ||
await stat(`${file}.4`) | ||
content = await readFile(`${file}.4`, 'utf8') | ||
ok(content.includes('#4'), 'third file contains fourth log') | ||
ok(content.includes('#5'), 'third file contains fifth log') | ||
ok(content.includes('#6'), 'third file contains sixth log') | ||
await stat(`${file}.5`) | ||
content = await readFile(`${file}.5`, 'utf8') | ||
ok(content.includes('#7'), 'fourth file contains seventh log') | ||
ok(content.includes('#6'), 'fourth file contains sixth log') | ||
await rejects(stat(`${file}.2`), 'resumed file was deleted') | ||
@@ -148,0 +147,0 @@ await rejects(stat(`${file}.6`), 'no other files created') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
26417
579
0