[READ-ONLY] Mirror of https://github.com/FoxxMD/logging. A typed, opinionated, batteries-included, Pino-based logging solution for backend TS/JS projects foxxmd.github.io/logging
child-logger logging logging-library nodejs pinojs typescript-library
0

Configure Feed

Select the types of activity you want to include in your feed.

test: Add test for pretty iso translateTime constant

FoxxMD (Mar 11, 2024, 3:11 PM EDT) 0d03411d cc47b0f6

+38 -5
+21 -4
package-lock.json
··· 17 17 "devDependencies": { 18 18 "@types/chai": "^4.3.0", 19 19 "@types/chai-as-promised": "^7.1.5", 20 + "@types/dateformat": "^5.0.2", 20 21 "@types/mocha": "^9.1.0", 21 22 "@types/node": "^18.0.0", 22 23 "chai": "^4.3.6", 23 24 "chai-as-promised": "^7.1.1", 25 + "dateformat": "^5.0.3", 24 26 "mocha": "^10.2.0", 25 27 "p-event": "^6.0.0", 26 28 "sinon": "^17.0.1", ··· 585 587 "@types/chai": "*" 586 588 } 587 589 }, 590 + "node_modules/@types/dateformat": { 591 + "version": "5.0.2", 592 + "resolved": "https://registry.npmjs.org/@types/dateformat/-/dateformat-5.0.2.tgz", 593 + "integrity": "sha512-M95hNBMa/hnwErH+a+VOD/sYgTmo15OTYTM2Hr52/e0OdOuY+Crag+kd3/ioZrhg0WGbl9Sm3hR7UU+MH6rfOw==", 594 + "dev": true 595 + }, 588 596 "node_modules/@types/mocha": { 589 597 "version": "9.1.1", 590 598 "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz", ··· 934 942 } 935 943 }, 936 944 "node_modules/dateformat": { 937 - "version": "4.6.3", 938 - "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", 939 - "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", 945 + "version": "5.0.3", 946 + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz", 947 + "integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==", 948 + "dev": true, 940 949 "engines": { 941 - "node": "*" 950 + "node": ">=12.20" 942 951 } 943 952 }, 944 953 "node_modules/debug": { ··· 1805 1814 }, 1806 1815 "bin": { 1807 1816 "pino-pretty": "bin.js" 1817 + } 1818 + }, 1819 + "node_modules/pino-pretty/node_modules/dateformat": { 1820 + "version": "4.6.3", 1821 + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", 1822 + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", 1823 + "engines": { 1824 + "node": "*" 1808 1825 } 1809 1826 }, 1810 1827 "node_modules/pino-roll": {
+2
package.json
··· 46 46 "devDependencies": { 47 47 "@types/chai": "^4.3.0", 48 48 "@types/chai-as-promised": "^7.1.5", 49 + "@types/dateformat": "^5.0.2", 49 50 "@types/mocha": "^9.1.0", 50 51 "@types/node": "^18.0.0", 51 52 "chai": "^4.3.6", 52 53 "chai-as-promised": "^7.1.1", 54 + "dateformat": "^5.0.3", 53 55 "mocha": "^10.2.0", 54 56 "p-event": "^6.0.0", 55 57 "sinon": "^17.0.1",
+15 -1
tests/index.test.ts
··· 12 12 import chai, {expect} from "chai"; 13 13 import {pEvent} from 'p-event'; 14 14 import {sleep} from "../src/util.js"; 15 - import {LogData, LOG_LEVEL_NAMES} from "../src/types.js"; 15 + import {LogData, LOG_LEVEL_NAMES, PRETTY_ISO8601} from "../src/types.js"; 16 16 import withLocalTmpDir from 'with-local-tmp-dir'; 17 17 import {readdirSync,} from 'node:fs'; 18 18 import {buildDestinationStream, buildDestinationRollingFile, buildDestinationFile} from "../src/destinations.js"; 19 19 import {buildLogger} from "../src/loggers.js"; 20 20 import {readFileSync} from "fs"; 21 21 import path from "path"; 22 + import dateFormatDef from "dateformat"; 23 + 24 + const dateFormat = dateFormatDef as unknown as typeof dateFormatDef.default; 22 25 23 26 24 27 const testConsoleLogger = (config?: object): [Logger, Transform, Transform] => { ··· 562 565 await sleep(10); 563 566 const formatted = (await formattedBuff).toString(); 564 567 expect(formatted).includes('DEBUG:'); 568 + }); 569 + 570 + it('ISO Pretty format prints correctly', async function () { 571 + const [logger, testStream, rawStream] = testAppLogger({file: false}, {pretty: {translateTime: PRETTY_ISO8601}}); 572 + const formattedBuff = pEvent(testStream, 'data'); 573 + 574 + const dt = dateFormat(new Date(), 'isoDateTime').substring(0, 19); 575 + logger.debug(`Test iso timestamp`); 576 + await sleep(10); 577 + const formatted = (await formattedBuff).toString(); 578 + expect(formatted).includes(dt); 565 579 }); 566 580 });