From c8baf8405fa866d8eda6a278f82af119e73002e2 Mon Sep 17 00:00:00 2001 From: Christophe Hurpeau Date: Wed, 1 May 2019 18:20:00 +0200 Subject: [PATCH] feat(nightingale-console): add options and json when not tty support custom formatter or output as options BREAKING CHANGE: output json by default when process.stdout.isTty is false --- .../dist/index-node10-dev.cjs.js | 13 +++++++--- .../dist/index-node10-dev.cjs.js.map | 2 +- .../dist/index-node10-dev.es.js | 13 +++++++--- .../dist/index-node10-dev.es.js.map | 2 +- .../dist/index-node10.cjs.js | 13 +++++++--- .../dist/index-node10.cjs.js.map | 2 +- .../dist/index-node10.es.js | 13 +++++++--- .../dist/index-node10.es.js.map | 2 +- .../dist/index-node8-dev.cjs.js | 13 +++++++--- .../dist/index-node8-dev.cjs.js.map | 2 +- .../dist/index-node8.cjs.js | 13 +++++++--- .../dist/index-node8.cjs.js.map | 2 +- packages/nightingale-console/dist/index.d.ts | 8 ------ .../nightingale-console/dist/index.d.ts.map | 1 - packages/nightingale-console/package.json | 1 + packages/nightingale-console/src/index.ts | 26 ++++++++++++++++--- 16 files changed, 89 insertions(+), 37 deletions(-) delete mode 100644 packages/nightingale-console/dist/index.d.ts delete mode 100644 packages/nightingale-console/dist/index.d.ts.map diff --git a/packages/nightingale-console/dist/index-node10-dev.cjs.js b/packages/nightingale-console/dist/index-node10-dev.cjs.js index 10fc9c19c..b83cec9ed 100644 --- a/packages/nightingale-console/dist/index-node10-dev.cjs.js +++ b/packages/nightingale-console/dist/index-node10-dev.cjs.js @@ -5,21 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } const formatterANSI = _interopDefault(require('nightingale-ansi-formatter')); +const formatterJSON = _interopDefault(require('nightingale-json-formatter')); const consoleOutput = _interopDefault(require('nightingale-console-output')); const createFindDebugLevel = _interopDefault(require('nightingale-debug')); const nightingaleTypes = require('nightingale-types'); -const handle = record => consoleOutput(formatterANSI(record), record); +const defaultFormatter = !process.stdout.isTTY ? formatterJSON : formatterANSI; + +const createHandle = (formatter = defaultFormatter, output = consoleOutput) => { + return record => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); class ConsoleHandler { - constructor(minLevel) { + constructor(minLevel, options = {}) { this.minLevel = nightingaleTypes.Level.ALL; this.minLevel = minLevel; this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } } diff --git a/packages/nightingale-console/dist/index-node10-dev.cjs.js.map b/packages/nightingale-console/dist/index-node10-dev.cjs.js.map index f11d19093..2fd8bab81 100644 --- a/packages/nightingale-console/dist/index-node10-dev.cjs.js.map +++ b/packages/nightingale-console/dist/index-node10-dev.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"index-node10-dev.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import formatterANSI from 'nightingale-ansi-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst handle: Handle = (record: LogRecord) =>\n consoleOutput(formatterANSI(record), record);\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = handle;\n }\n}\n"],"names":["handle","record","consoleOutput","formatterANSI","findDebugLevel","createFindDebugLevel","process","env","DEBUG","ConsoleHandler","constructor","minLevel","Level","ALL","isHandling","level","key"],"mappings":";;;;;;;;;;;AAKA,MAAMA,MAAc,GAAOC,MAAJ,IACrBC,aAAa,CAACC,aAAa,CAACF,MAAD,CAAd,EAAwBA,MAAxB,CADf;;AAEA,MAAMG,cAAc,GAAGC,oBAAoB,CAACC,OAAO,CAACC,GAAR,CAAYC,KAAb,CAA3C;AAEA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkB;SAN7BA,QAM6B,GANXC,sBAAK,CAACC,GAMK;SACtBF,QAAL,GAAgBA,QAAhB;;SACKG,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACO,QAAD,EAAWK,GAAX,CADzB;;SAEKhB,MAAL,GAAcA,MAAd;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index-node10-dev.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { POB_TARGET } from 'pob-babel';\nimport formatterANSI from 'nightingale-ansi-formatter';\nimport formatterJSON from 'nightingale-json-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst defaultFormatter =\n POB_TARGET === 'node' && !process.stdout.isTTY\n ? formatterJSON\n : formatterANSI;\n\nconst createHandle = (\n formatter = defaultFormatter,\n output = consoleOutput,\n): Handle => {\n return (record: LogRecord): void => {\n return output(formatter(record), record);\n };\n};\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\ninterface ConsoleHandlerOptions {\n formatter?: (record: LogRecord) => string;\n output?: (param: string | string[], record: LogRecord) => void;\n}\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = createHandle(options.formatter, options.output);\n }\n}\n"],"names":["defaultFormatter","process","stdout","isTTY","formatterJSON","formatterANSI","createHandle","formatter","output","consoleOutput","record","findDebugLevel","createFindDebugLevel","env","DEBUG","ConsoleHandler","constructor","minLevel","options","Level","ALL","isHandling","level","key","handle"],"mappings":";;;;;;;;;;;;AAOA,MAAMA,gBAAgB,GACK,CAACC,OAAO,CAACC,MAAR,CAAeC,KAAzC,GACIC,aADJ,GAEIC,aAHN;;AAKA,MAAMC,YAAY,GAAG,CACnBC,SAAS,GAAGP,gBADO,EAEnBQ,MAAM,GAAGC,aAFU,KAGR;SACAC,MAAJ,IAAmC;WACjCF,MAAM,CAACD,SAAS,CAACG,MAAD,CAAV,EAAoBA,MAApB,CAAb;GADF;CAJF;;AAQA,MAAMC,cAAc,GAAGC,oBAAoB,CAACX,OAAO,CAACY,GAAR,CAAYC,KAAb,CAA3C;AAOA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkBC,OAA8B,GAAG,EAAnD,EAAuD;SANlED,QAMkE,GANhDE,sBAAK,CAACC,GAM0C;SAC3DH,QAAL,GAAgBA,QAAhB;;SACKI,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACM,QAAD,EAAWM,GAAX,CADzB;;SAEKC,MAAL,GAAclB,YAAY,CAACY,OAAO,CAACX,SAAT,EAAoBW,OAAO,CAACV,MAA5B,CAA1B;;;;;;;"} \ No newline at end of file diff --git a/packages/nightingale-console/dist/index-node10-dev.es.js b/packages/nightingale-console/dist/index-node10-dev.es.js index 2ac765fcb..db1cd2b75 100644 --- a/packages/nightingale-console/dist/index-node10-dev.es.js +++ b/packages/nightingale-console/dist/index-node10-dev.es.js @@ -1,19 +1,26 @@ import formatterANSI from 'nightingale-ansi-formatter'; +import formatterJSON from 'nightingale-json-formatter'; import consoleOutput from 'nightingale-console-output'; import createFindDebugLevel from 'nightingale-debug'; import { Level } from 'nightingale-types'; -const handle = record => consoleOutput(formatterANSI(record), record); +const defaultFormatter = !process.stdout.isTTY ? formatterJSON : formatterANSI; + +const createHandle = (formatter = defaultFormatter, output = consoleOutput) => { + return record => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); class ConsoleHandler { - constructor(minLevel) { + constructor(minLevel, options = {}) { this.minLevel = Level.ALL; this.minLevel = minLevel; this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } } diff --git a/packages/nightingale-console/dist/index-node10-dev.es.js.map b/packages/nightingale-console/dist/index-node10-dev.es.js.map index b863a85c6..a29cc9007 100644 --- a/packages/nightingale-console/dist/index-node10-dev.es.js.map +++ b/packages/nightingale-console/dist/index-node10-dev.es.js.map @@ -1 +1 @@ -{"version":3,"file":"index-node10-dev.es.js","sources":["../src/index.ts"],"sourcesContent":["import formatterANSI from 'nightingale-ansi-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst handle: Handle = (record: LogRecord) =>\n consoleOutput(formatterANSI(record), record);\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = handle;\n }\n}\n"],"names":["handle","record","consoleOutput","formatterANSI","findDebugLevel","createFindDebugLevel","process","env","DEBUG","ConsoleHandler","constructor","minLevel","Level","ALL","isHandling","level","key"],"mappings":";;;;;AAKA,MAAMA,MAAc,GAAOC,MAAJ,IACrBC,aAAa,CAACC,aAAa,CAACF,MAAD,CAAd,EAAwBA,MAAxB,CADf;;AAEA,MAAMG,cAAc,GAAGC,oBAAoB,CAACC,OAAO,CAACC,GAAR,CAAYC,KAAb,CAA3C;AAEA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkB;SAN7BA,QAM6B,GANXC,KAAK,CAACC,GAMK;SACtBF,QAAL,GAAgBA,QAAhB;;SACKG,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACO,QAAD,EAAWK,GAAX,CADzB;;SAEKhB,MAAL,GAAcA,MAAd;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index-node10-dev.es.js","sources":["../src/index.ts"],"sourcesContent":["import { POB_TARGET } from 'pob-babel';\nimport formatterANSI from 'nightingale-ansi-formatter';\nimport formatterJSON from 'nightingale-json-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst defaultFormatter =\n POB_TARGET === 'node' && !process.stdout.isTTY\n ? formatterJSON\n : formatterANSI;\n\nconst createHandle = (\n formatter = defaultFormatter,\n output = consoleOutput,\n): Handle => {\n return (record: LogRecord): void => {\n return output(formatter(record), record);\n };\n};\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\ninterface ConsoleHandlerOptions {\n formatter?: (record: LogRecord) => string;\n output?: (param: string | string[], record: LogRecord) => void;\n}\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = createHandle(options.formatter, options.output);\n }\n}\n"],"names":["defaultFormatter","process","stdout","isTTY","formatterJSON","formatterANSI","createHandle","formatter","output","consoleOutput","record","findDebugLevel","createFindDebugLevel","env","DEBUG","ConsoleHandler","constructor","minLevel","options","Level","ALL","isHandling","level","key","handle"],"mappings":";;;;;;AAOA,MAAMA,gBAAgB,GACK,CAACC,OAAO,CAACC,MAAR,CAAeC,KAAzC,GACIC,aADJ,GAEIC,aAHN;;AAKA,MAAMC,YAAY,GAAG,CACnBC,SAAS,GAAGP,gBADO,EAEnBQ,MAAM,GAAGC,aAFU,KAGR;SACAC,MAAJ,IAAmC;WACjCF,MAAM,CAACD,SAAS,CAACG,MAAD,CAAV,EAAoBA,MAApB,CAAb;GADF;CAJF;;AAQA,MAAMC,cAAc,GAAGC,oBAAoB,CAACX,OAAO,CAACY,GAAR,CAAYC,KAAb,CAA3C;AAOA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkBC,OAA8B,GAAG,EAAnD,EAAuD;SANlED,QAMkE,GANhDE,KAAK,CAACC,GAM0C;SAC3DH,QAAL,GAAgBA,QAAhB;;SACKI,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACM,QAAD,EAAWM,GAAX,CADzB;;SAEKC,MAAL,GAAclB,YAAY,CAACY,OAAO,CAACX,SAAT,EAAoBW,OAAO,CAACV,MAA5B,CAA1B;;;;;;;"} \ No newline at end of file diff --git a/packages/nightingale-console/dist/index-node10.cjs.js b/packages/nightingale-console/dist/index-node10.cjs.js index 46f1133f2..e366dd0b2 100644 --- a/packages/nightingale-console/dist/index-node10.cjs.js +++ b/packages/nightingale-console/dist/index-node10.cjs.js @@ -5,21 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } const formatterANSI = _interopDefault(require('nightingale-ansi-formatter')); +const formatterJSON = _interopDefault(require('nightingale-json-formatter')); const consoleOutput = _interopDefault(require('nightingale-console-output')); const createFindDebugLevel = _interopDefault(require('nightingale-debug')); const nightingaleTypes = require('nightingale-types'); -const handle = record => consoleOutput(formatterANSI(record), record); +const defaultFormatter = !process.stdout.isTTY ? formatterJSON : formatterANSI; + +const createHandle = (formatter = defaultFormatter, output = consoleOutput) => { + return record => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); class ConsoleHandler { - constructor(minLevel) { + constructor(minLevel, options = {}) { this.minLevel = nightingaleTypes.Level.ALL; this.minLevel = minLevel; this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } } diff --git a/packages/nightingale-console/dist/index-node10.cjs.js.map b/packages/nightingale-console/dist/index-node10.cjs.js.map index cfbee3c1a..058ed0c0b 100644 --- a/packages/nightingale-console/dist/index-node10.cjs.js.map +++ b/packages/nightingale-console/dist/index-node10.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"index-node10.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import formatterANSI from 'nightingale-ansi-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst handle: Handle = (record: LogRecord) =>\n consoleOutput(formatterANSI(record), record);\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = handle;\n }\n}\n"],"names":["handle","record","consoleOutput","formatterANSI","findDebugLevel","createFindDebugLevel","process","env","DEBUG","ConsoleHandler","constructor","minLevel","Level","ALL","isHandling","level","key"],"mappings":";;;;;;;;;;;AAKA,MAAMA,MAAc,GAAOC,MAAJ,IACrBC,aAAa,CAACC,aAAa,CAACF,MAAD,CAAd,EAAwBA,MAAxB,CADf;;AAEA,MAAMG,cAAc,GAAGC,oBAAoB,CAACC,OAAO,CAACC,GAAR,CAAYC,KAAb,CAA3C;AAEA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkB;SAN7BA,QAM6B,GANXC,sBAAK,CAACC,GAMK;SACtBF,QAAL,GAAgBA,QAAhB;;SACKG,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACO,QAAD,EAAWK,GAAX,CADzB;;SAEKhB,MAAL,GAAcA,MAAd;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index-node10.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { POB_TARGET } from 'pob-babel';\nimport formatterANSI from 'nightingale-ansi-formatter';\nimport formatterJSON from 'nightingale-json-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst defaultFormatter =\n POB_TARGET === 'node' && !process.stdout.isTTY\n ? formatterJSON\n : formatterANSI;\n\nconst createHandle = (\n formatter = defaultFormatter,\n output = consoleOutput,\n): Handle => {\n return (record: LogRecord): void => {\n return output(formatter(record), record);\n };\n};\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\ninterface ConsoleHandlerOptions {\n formatter?: (record: LogRecord) => string;\n output?: (param: string | string[], record: LogRecord) => void;\n}\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = createHandle(options.formatter, options.output);\n }\n}\n"],"names":["defaultFormatter","process","stdout","isTTY","formatterJSON","formatterANSI","createHandle","formatter","output","consoleOutput","record","findDebugLevel","createFindDebugLevel","env","DEBUG","ConsoleHandler","constructor","minLevel","options","Level","ALL","isHandling","level","key","handle"],"mappings":";;;;;;;;;;;;AAOA,MAAMA,gBAAgB,GACK,CAACC,OAAO,CAACC,MAAR,CAAeC,KAAzC,GACIC,aADJ,GAEIC,aAHN;;AAKA,MAAMC,YAAY,GAAG,CACnBC,SAAS,GAAGP,gBADO,EAEnBQ,MAAM,GAAGC,aAFU,KAGR;SACAC,MAAJ,IAAmC;WACjCF,MAAM,CAACD,SAAS,CAACG,MAAD,CAAV,EAAoBA,MAApB,CAAb;GADF;CAJF;;AAQA,MAAMC,cAAc,GAAGC,oBAAoB,CAACX,OAAO,CAACY,GAAR,CAAYC,KAAb,CAA3C;AAOA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkBC,OAA8B,GAAG,EAAnD,EAAuD;SANlED,QAMkE,GANhDE,sBAAK,CAACC,GAM0C;SAC3DH,QAAL,GAAgBA,QAAhB;;SACKI,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACM,QAAD,EAAWM,GAAX,CADzB;;SAEKC,MAAL,GAAclB,YAAY,CAACY,OAAO,CAACX,SAAT,EAAoBW,OAAO,CAACV,MAA5B,CAA1B;;;;;;;"} \ No newline at end of file diff --git a/packages/nightingale-console/dist/index-node10.es.js b/packages/nightingale-console/dist/index-node10.es.js index 19fd2b9cb..46b4c3cee 100644 --- a/packages/nightingale-console/dist/index-node10.es.js +++ b/packages/nightingale-console/dist/index-node10.es.js @@ -1,19 +1,26 @@ import formatterANSI from 'nightingale-ansi-formatter'; +import formatterJSON from 'nightingale-json-formatter'; import consoleOutput from 'nightingale-console-output'; import createFindDebugLevel from 'nightingale-debug'; import { Level } from 'nightingale-types'; -const handle = record => consoleOutput(formatterANSI(record), record); +const defaultFormatter = !process.stdout.isTTY ? formatterJSON : formatterANSI; + +const createHandle = (formatter = defaultFormatter, output = consoleOutput) => { + return record => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); class ConsoleHandler { - constructor(minLevel) { + constructor(minLevel, options = {}) { this.minLevel = Level.ALL; this.minLevel = minLevel; this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } } diff --git a/packages/nightingale-console/dist/index-node10.es.js.map b/packages/nightingale-console/dist/index-node10.es.js.map index 1d5104143..2c49031dc 100644 --- a/packages/nightingale-console/dist/index-node10.es.js.map +++ b/packages/nightingale-console/dist/index-node10.es.js.map @@ -1 +1 @@ -{"version":3,"file":"index-node10.es.js","sources":["../src/index.ts"],"sourcesContent":["import formatterANSI from 'nightingale-ansi-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst handle: Handle = (record: LogRecord) =>\n consoleOutput(formatterANSI(record), record);\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = handle;\n }\n}\n"],"names":["handle","record","consoleOutput","formatterANSI","findDebugLevel","createFindDebugLevel","process","env","DEBUG","ConsoleHandler","constructor","minLevel","Level","ALL","isHandling","level","key"],"mappings":";;;;;AAKA,MAAMA,MAAc,GAAOC,MAAJ,IACrBC,aAAa,CAACC,aAAa,CAACF,MAAD,CAAd,EAAwBA,MAAxB,CADf;;AAEA,MAAMG,cAAc,GAAGC,oBAAoB,CAACC,OAAO,CAACC,GAAR,CAAYC,KAAb,CAA3C;AAEA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkB;SAN7BA,QAM6B,GANXC,KAAK,CAACC,GAMK;SACtBF,QAAL,GAAgBA,QAAhB;;SACKG,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACO,QAAD,EAAWK,GAAX,CADzB;;SAEKhB,MAAL,GAAcA,MAAd;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index-node10.es.js","sources":["../src/index.ts"],"sourcesContent":["import { POB_TARGET } from 'pob-babel';\nimport formatterANSI from 'nightingale-ansi-formatter';\nimport formatterJSON from 'nightingale-json-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst defaultFormatter =\n POB_TARGET === 'node' && !process.stdout.isTTY\n ? formatterJSON\n : formatterANSI;\n\nconst createHandle = (\n formatter = defaultFormatter,\n output = consoleOutput,\n): Handle => {\n return (record: LogRecord): void => {\n return output(formatter(record), record);\n };\n};\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\ninterface ConsoleHandlerOptions {\n formatter?: (record: LogRecord) => string;\n output?: (param: string | string[], record: LogRecord) => void;\n}\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = createHandle(options.formatter, options.output);\n }\n}\n"],"names":["defaultFormatter","process","stdout","isTTY","formatterJSON","formatterANSI","createHandle","formatter","output","consoleOutput","record","findDebugLevel","createFindDebugLevel","env","DEBUG","ConsoleHandler","constructor","minLevel","options","Level","ALL","isHandling","level","key","handle"],"mappings":";;;;;;AAOA,MAAMA,gBAAgB,GACK,CAACC,OAAO,CAACC,MAAR,CAAeC,KAAzC,GACIC,aADJ,GAEIC,aAHN;;AAKA,MAAMC,YAAY,GAAG,CACnBC,SAAS,GAAGP,gBADO,EAEnBQ,MAAM,GAAGC,aAFU,KAGR;SACAC,MAAJ,IAAmC;WACjCF,MAAM,CAACD,SAAS,CAACG,MAAD,CAAV,EAAoBA,MAApB,CAAb;GADF;CAJF;;AAQA,MAAMC,cAAc,GAAGC,oBAAoB,CAACX,OAAO,CAACY,GAAR,CAAYC,KAAb,CAA3C;AAOA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkBC,OAA8B,GAAG,EAAnD,EAAuD;SANlED,QAMkE,GANhDE,KAAK,CAACC,GAM0C;SAC3DH,QAAL,GAAgBA,QAAhB;;SACKI,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACM,QAAD,EAAWM,GAAX,CADzB;;SAEKC,MAAL,GAAclB,YAAY,CAACY,OAAO,CAACX,SAAT,EAAoBW,OAAO,CAACV,MAA5B,CAA1B;;;;;;;"} \ No newline at end of file diff --git a/packages/nightingale-console/dist/index-node8-dev.cjs.js b/packages/nightingale-console/dist/index-node8-dev.cjs.js index 97f110683..c0b866492 100644 --- a/packages/nightingale-console/dist/index-node8-dev.cjs.js +++ b/packages/nightingale-console/dist/index-node8-dev.cjs.js @@ -5,21 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } const formatterANSI = _interopDefault(require('nightingale-ansi-formatter')); +const formatterJSON = _interopDefault(require('nightingale-json-formatter')); const consoleOutput = _interopDefault(require('nightingale-console-output')); const createFindDebugLevel = _interopDefault(require('nightingale-debug')); const nightingaleTypes = require('nightingale-types'); -const handle = record => consoleOutput(formatterANSI(record), record); +const defaultFormatter = !process.stdout.isTTY ? formatterJSON : formatterANSI; + +const createHandle = (formatter = defaultFormatter, output = consoleOutput) => { + return record => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); class ConsoleHandler { - constructor(minLevel) { + constructor(minLevel, options = {}) { this.minLevel = nightingaleTypes.Level.ALL; this.minLevel = minLevel; this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } } diff --git a/packages/nightingale-console/dist/index-node8-dev.cjs.js.map b/packages/nightingale-console/dist/index-node8-dev.cjs.js.map index a3eef1dda..63373e642 100644 --- a/packages/nightingale-console/dist/index-node8-dev.cjs.js.map +++ b/packages/nightingale-console/dist/index-node8-dev.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"index-node8-dev.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import formatterANSI from 'nightingale-ansi-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst handle: Handle = (record: LogRecord) =>\n consoleOutput(formatterANSI(record), record);\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = handle;\n }\n}\n"],"names":["handle","record","consoleOutput","formatterANSI","findDebugLevel","createFindDebugLevel","process","env","DEBUG","ConsoleHandler","constructor","minLevel","Level","ALL","isHandling","level","key"],"mappings":";;;;;;;;;;;AAKA,MAAMA,MAAc,GAAOC,MAAJ,IACrBC,aAAa,CAACC,aAAa,CAACF,MAAD,CAAd,EAAwBA,MAAxB,CADf;;AAEA,MAAMG,cAAc,GAAGC,oBAAoB,CAACC,OAAO,CAACC,GAAR,CAAYC,KAAb,CAA3C;AAEA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkB;SAN7BA,QAM6B,GANXC,sBAAK,CAACC,GAMK;SACtBF,QAAL,GAAgBA,QAAhB;;SACKG,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACO,QAAD,EAAWK,GAAX,CADzB;;SAEKhB,MAAL,GAAcA,MAAd;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index-node8-dev.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { POB_TARGET } from 'pob-babel';\nimport formatterANSI from 'nightingale-ansi-formatter';\nimport formatterJSON from 'nightingale-json-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst defaultFormatter =\n POB_TARGET === 'node' && !process.stdout.isTTY\n ? formatterJSON\n : formatterANSI;\n\nconst createHandle = (\n formatter = defaultFormatter,\n output = consoleOutput,\n): Handle => {\n return (record: LogRecord): void => {\n return output(formatter(record), record);\n };\n};\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\ninterface ConsoleHandlerOptions {\n formatter?: (record: LogRecord) => string;\n output?: (param: string | string[], record: LogRecord) => void;\n}\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = createHandle(options.formatter, options.output);\n }\n}\n"],"names":["defaultFormatter","process","stdout","isTTY","formatterJSON","formatterANSI","createHandle","formatter","output","consoleOutput","record","findDebugLevel","createFindDebugLevel","env","DEBUG","ConsoleHandler","constructor","minLevel","options","Level","ALL","isHandling","level","key","handle"],"mappings":";;;;;;;;;;;;AAOA,MAAMA,gBAAgB,GACK,CAACC,OAAO,CAACC,MAAR,CAAeC,KAAzC,GACIC,aADJ,GAEIC,aAHN;;AAKA,MAAMC,YAAY,GAAG,CACnBC,SAAS,GAAGP,gBADO,EAEnBQ,MAAM,GAAGC,aAFU,KAGR;SACAC,MAAJ,IAAmC;WACjCF,MAAM,CAACD,SAAS,CAACG,MAAD,CAAV,EAAoBA,MAApB,CAAb;GADF;CAJF;;AAQA,MAAMC,cAAc,GAAGC,oBAAoB,CAACX,OAAO,CAACY,GAAR,CAAYC,KAAb,CAA3C;AAOA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkBC,OAA8B,GAAG,EAAnD,EAAuD;SANlED,QAMkE,GANhDE,sBAAK,CAACC,GAM0C;SAC3DH,QAAL,GAAgBA,QAAhB;;SACKI,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACM,QAAD,EAAWM,GAAX,CADzB;;SAEKC,MAAL,GAAclB,YAAY,CAACY,OAAO,CAACX,SAAT,EAAoBW,OAAO,CAACV,MAA5B,CAA1B;;;;;;;"} \ No newline at end of file diff --git a/packages/nightingale-console/dist/index-node8.cjs.js b/packages/nightingale-console/dist/index-node8.cjs.js index 4ece132db..ed8e3014e 100644 --- a/packages/nightingale-console/dist/index-node8.cjs.js +++ b/packages/nightingale-console/dist/index-node8.cjs.js @@ -5,21 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } const formatterANSI = _interopDefault(require('nightingale-ansi-formatter')); +const formatterJSON = _interopDefault(require('nightingale-json-formatter')); const consoleOutput = _interopDefault(require('nightingale-console-output')); const createFindDebugLevel = _interopDefault(require('nightingale-debug')); const nightingaleTypes = require('nightingale-types'); -const handle = record => consoleOutput(formatterANSI(record), record); +const defaultFormatter = !process.stdout.isTTY ? formatterJSON : formatterANSI; + +const createHandle = (formatter = defaultFormatter, output = consoleOutput) => { + return record => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); class ConsoleHandler { - constructor(minLevel) { + constructor(minLevel, options = {}) { this.minLevel = nightingaleTypes.Level.ALL; this.minLevel = minLevel; this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } } diff --git a/packages/nightingale-console/dist/index-node8.cjs.js.map b/packages/nightingale-console/dist/index-node8.cjs.js.map index 9da94b937..015449053 100644 --- a/packages/nightingale-console/dist/index-node8.cjs.js.map +++ b/packages/nightingale-console/dist/index-node8.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"index-node8.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import formatterANSI from 'nightingale-ansi-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst handle: Handle = (record: LogRecord) =>\n consoleOutput(formatterANSI(record), record);\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = handle;\n }\n}\n"],"names":["handle","record","consoleOutput","formatterANSI","findDebugLevel","createFindDebugLevel","process","env","DEBUG","ConsoleHandler","constructor","minLevel","Level","ALL","isHandling","level","key"],"mappings":";;;;;;;;;;;AAKA,MAAMA,MAAc,GAAOC,MAAJ,IACrBC,aAAa,CAACC,aAAa,CAACF,MAAD,CAAd,EAAwBA,MAAxB,CADf;;AAEA,MAAMG,cAAc,GAAGC,oBAAoB,CAACC,OAAO,CAACC,GAAR,CAAYC,KAAb,CAA3C;AAEA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkB;SAN7BA,QAM6B,GANXC,sBAAK,CAACC,GAMK;SACtBF,QAAL,GAAgBA,QAAhB;;SACKG,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACO,QAAD,EAAWK,GAAX,CADzB;;SAEKhB,MAAL,GAAcA,MAAd;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index-node8.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { POB_TARGET } from 'pob-babel';\nimport formatterANSI from 'nightingale-ansi-formatter';\nimport formatterJSON from 'nightingale-json-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport createFindDebugLevel from 'nightingale-debug';\nimport { IsHandling, Handle, LogRecord, Level } from 'nightingale-types';\n\nconst defaultFormatter =\n POB_TARGET === 'node' && !process.stdout.isTTY\n ? formatterJSON\n : formatterANSI;\n\nconst createHandle = (\n formatter = defaultFormatter,\n output = consoleOutput,\n): Handle => {\n return (record: LogRecord): void => {\n return output(formatter(record), record);\n };\n};\nconst findDebugLevel = createFindDebugLevel(process.env.DEBUG);\n\ninterface ConsoleHandlerOptions {\n formatter?: (record: LogRecord) => string;\n output?: (param: string | string[], record: LogRecord) => void;\n}\n\nexport default class ConsoleHandler {\n minLevel: Level = Level.ALL;\n\n isHandling: IsHandling;\n\n handle: Handle;\n\n constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {\n this.minLevel = minLevel;\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n this.handle = createHandle(options.formatter, options.output);\n }\n}\n"],"names":["defaultFormatter","process","stdout","isTTY","formatterJSON","formatterANSI","createHandle","formatter","output","consoleOutput","record","findDebugLevel","createFindDebugLevel","env","DEBUG","ConsoleHandler","constructor","minLevel","options","Level","ALL","isHandling","level","key","handle"],"mappings":";;;;;;;;;;;;AAOA,MAAMA,gBAAgB,GACK,CAACC,OAAO,CAACC,MAAR,CAAeC,KAAzC,GACIC,aADJ,GAEIC,aAHN;;AAKA,MAAMC,YAAY,GAAG,CACnBC,SAAS,GAAGP,gBADO,EAEnBQ,MAAM,GAAGC,aAFU,KAGR;SACAC,MAAJ,IAAmC;WACjCF,MAAM,CAACD,SAAS,CAACG,MAAD,CAAV,EAAoBA,MAApB,CAAb;GADF;CAJF;;AAQA,MAAMC,cAAc,GAAGC,oBAAoB,CAACX,OAAO,CAACY,GAAR,CAAYC,KAAb,CAA3C;AAOA,AAAe,MAAMC,cAAN,CAAqB;EAOlCC,WAAW,CAACC,QAAD,EAAkBC,OAA8B,GAAG,EAAnD,EAAuD;SANlED,QAMkE,GANhDE,sBAAK,CAACC,GAM0C;SAC3DH,QAAL,GAAgBA,QAAhB;;SACKI,UAAL,GAAkB,CAACC,KAAD,EAAeC,GAAf,KAChBD,KAAK,IAAIX,cAAc,CAACM,QAAD,EAAWM,GAAX,CADzB;;SAEKC,MAAL,GAAclB,YAAY,CAACY,OAAO,CAACX,SAAT,EAAoBW,OAAO,CAACV,MAA5B,CAA1B;;;;;;;"} \ No newline at end of file diff --git a/packages/nightingale-console/dist/index.d.ts b/packages/nightingale-console/dist/index.d.ts deleted file mode 100644 index 0f7298037..000000000 --- a/packages/nightingale-console/dist/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IsHandling, Handle, Level } from 'nightingale-types'; -export default class ConsoleHandler { - minLevel: Level; - isHandling: IsHandling; - handle: Handle; - constructor(minLevel: Level); -} -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/nightingale-console/dist/index.d.ts.map b/packages/nightingale-console/dist/index.d.ts.map deleted file mode 100644 index 156712e2c..000000000 --- a/packages/nightingale-console/dist/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAa,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAMzE,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,QAAQ,EAAE,KAAK,CAAa;IAE5B,UAAU,EAAE,UAAU,CAAC;IAEvB,MAAM,EAAE,MAAM,CAAC;gBAEH,QAAQ,EAAE,KAAK;CAM5B"} \ No newline at end of file diff --git a/packages/nightingale-console/package.json b/packages/nightingale-console/package.json index 7fbd184d6..9a2513fd8 100644 --- a/packages/nightingale-console/package.json +++ b/packages/nightingale-console/package.json @@ -34,6 +34,7 @@ "nightingale-ansi-formatter": "^4.2.1", "nightingale-console-output": "^4.2.1", "nightingale-debug": "^5.2.1", + "nightingale-json-formatter": "^4.2.1", "nightingale-types": "^2.2.1" }, "devDependencies": { diff --git a/packages/nightingale-console/src/index.ts b/packages/nightingale-console/src/index.ts index 6cd3690c1..62793d0b0 100644 --- a/packages/nightingale-console/src/index.ts +++ b/packages/nightingale-console/src/index.ts @@ -1,12 +1,30 @@ +import { POB_TARGET } from 'pob-babel'; import formatterANSI from 'nightingale-ansi-formatter'; +import formatterJSON from 'nightingale-json-formatter'; import consoleOutput from 'nightingale-console-output'; import createFindDebugLevel from 'nightingale-debug'; import { IsHandling, Handle, LogRecord, Level } from 'nightingale-types'; -const handle: Handle = (record: LogRecord) => - consoleOutput(formatterANSI(record), record); +const defaultFormatter = + POB_TARGET === 'node' && !process.stdout.isTTY + ? formatterJSON + : formatterANSI; + +const createHandle = ( + formatter = defaultFormatter, + output = consoleOutput, +): Handle => { + return (record: LogRecord): void => { + return output(formatter(record), record); + }; +}; const findDebugLevel = createFindDebugLevel(process.env.DEBUG); +interface ConsoleHandlerOptions { + formatter?: (record: LogRecord) => string; + output?: (param: string | string[], record: LogRecord) => void; +} + export default class ConsoleHandler { minLevel: Level = Level.ALL; @@ -14,10 +32,10 @@ export default class ConsoleHandler { handle: Handle; - constructor(minLevel: Level) { + constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) { this.minLevel = minLevel; this.isHandling = (level: Level, key: string) => level >= findDebugLevel(minLevel, key); - this.handle = handle; + this.handle = createHandle(options.formatter, options.output); } }