standard-log 6.3.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE9C,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAyBnF,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE9C,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAgCnF,CAAA"}
package/lib/config.js CHANGED
@@ -6,11 +6,19 @@ var type_plus_1 = require("type-plus");
6
6
  var customLogLevel_1 = require("./customLogLevel");
7
7
  var errors_1 = require("./errors");
8
8
  var getDefaultReporter_1 = require("./getDefaultReporter");
9
+ var getLogger_1 = require("./getLogger");
9
10
  var store_1 = require("./store");
10
11
  exports.config = function config(options) {
11
12
  if (options === void 0) { options = {}; }
12
- if (store_1.store.value.configured && store_1.store.value.mode === 'production') {
13
- throw new errors_1.ProhibitedDuringProduction('config');
13
+ if (store_1.store.value.configured) {
14
+ if (store_1.store.value.mode === 'production') {
15
+ throw new errors_1.ProhibitedDuringProduction('config');
16
+ }
17
+ if (store_1.store.value.mode === 'test') {
18
+ var log = (0, getLogger_1.getLogger)('standard-log');
19
+ log.warn("already configured for test, ignoring config() call");
20
+ return;
21
+ }
14
22
  }
15
23
  if (options.mode)
16
24
  store_1.store.value.mode = options.mode;
package/lib/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;AAAA,uCAAsC;AACtC,mDAAoD;AACpD,mCAAqD;AACrD,2DAAyD;AACzD,iCAA+B;AAUlB,QAAA,MAAM,GAA6E,SAAS,MAAM,CAAC,OAAoC;IAApC,wBAAA,EAAA,YAAoC;IAClJ,IAAI,aAAK,CAAC,KAAK,CAAC,UAAU,IAAI,aAAK,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;QAC/D,MAAM,IAAI,mCAA0B,CAAC,QAAQ,CAAC,CAAA;KAC/C;IAED,IAAI,OAAO,CAAC,IAAI;QAAE,aAAK,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAEjD,aAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAK,CAAC,KAAK,CAAC,QAAQ,CAAA;IAE/F,IAAI,OAAO,CAAC,YAAY,EAAE;QACxB,IAAM,cAAY,GAAG,OAAO,CAAC,YAAY,CAAA;QACzC,IAAA,sBAAU,EAAC,cAAY,EAAE,UAAA,CAAC;YACxB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AU,CAAA;IAC/B,CAAC;CACF,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"configForTest.d.ts","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ;;EAQhD"}
1
+ {"version":3,"file":"configForTest.d.ts","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ;;EAShD"}
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configForTest = void 0;
4
4
  var config_1 = require("./config");
5
5
  var memory_1 = require("./memory");
6
+ var store_1 = require("./store");
6
7
  function configForTest(logLevel) {
8
+ store_1.store.reset();
7
9
  var reporter = (0, memory_1.createMemoryLogReporter)();
8
10
  (0, config_1.config)({
9
11
  reporters: [reporter],
@@ -1 +1 @@
1
- {"version":3,"file":"configForTest.js","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,mCAAkD;AAIlD,SAAgB,aAAa,CAAC,QAAmB;IAC/C,IAAM,QAAQ,GAAG,IAAA,gCAAuB,GAAE,CAAA;IAC1C,IAAA,eAAM,EAAC;QACL,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,IAAI,EAAE,MAAM;QACZ,QAAQ,UAAA;KACT,CAAC,CAAA;IACF,OAAO,EAAE,QAAQ,UAAA,EAAE,CAAA;AACrB,CAAC;AARD,sCAQC"}
1
+ {"version":3,"file":"configForTest.js","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,mCAAkD;AAClD,iCAA+B;AAI/B,SAAgB,aAAa,CAAC,QAAmB;IAC/C,aAAK,CAAC,KAAK,EAAE,CAAA;IACb,IAAM,QAAQ,GAAG,IAAA,gCAAuB,GAAE,CAAA;IAC1C,IAAA,eAAM,EAAC;QACL,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,IAAI,EAAE,MAAM;QACZ,QAAQ,UAAA;KACT,CAAC,CAAA;IACF,OAAO,EAAE,QAAQ,UAAA,EAAE,CAAA;AACrB,CAAC;AATD,sCASC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryLogReporter.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAa,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI7F,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAUvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAIlD;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CA4BjG"}
1
+ {"version":3,"file":"MemoryLogReporter.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAa,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI7F,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAUvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CA4BjG"}
@@ -15,7 +15,11 @@ function createGetLogMessage() {
15
15
  function toMessageWithLevel(logs) {
16
16
  return logs.map(toInspectStringForObject_1.toInspectLogEntry)
17
17
  .map(function (log) { return "".concat((0, formatter_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); })
18
- .join('\n');
18
+ .join('\n')
19
+ // if it has more than this log,
20
+ // we assume it is running under tests,
21
+ // and remove this log to simplify testing.
22
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\\n.+/, '');
19
23
  }
20
24
  exports.toMessageWithLevel = toMessageWithLevel;
21
25
  function createMemoryLogReporter(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryLogReporter.js","sourceRoot":"","sources":["../../src/memory/MemoryLogReporter.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,0CAA6C;AAE7C,kCAAuD;AACvD,uEAA8D;AAc9D,SAAS,mBAAmB;IAC1B,OAAO,SAAS,aAAa;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,4CAAiB,CAAC;aACpC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAlB,CAAkB,CAAC;aAC9B,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAED,SAAgB,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,4CAAiB,CAAC;SAC/B,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,IAAA,0BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI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SAAS,GAAG,KAAK,CAAA;QACnB,CAAC;QACD,IAAI,MAAM;YACR,OAAO,MAAM,CAAA;QACf,CAAC;QACD,IAAI,MAAM,CAAC,KAAgB;YACzB,IAAA,oCAA4B,EAAC,qBAAqB,CAAC,CAAA;YACnD,MAAM,GAAG,KAAK,CAAA;QAChB,CAAC;QACD,IAAI,EAAE,EAAE;QACR,KAAK,YAAC,KAAK;YACT,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;QAClC,CAAC;QACD,aAAa,EAAE,mBAAmB,EAAE;QACpC,sBAAsB,gBAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;KAClE,CAAA;AACH,CAAC;AA5BD,0DA4BC"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE9C,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAyBnF,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE9C,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAgCnF,CAAA"}
package/libm/config.js CHANGED
@@ -2,10 +2,18 @@ import { forEachKey } from 'type-plus';
2
2
  import { addCustomLogLevel } from './customLogLevel';
3
3
  import { ProhibitedDuringProduction } from './errors';
4
4
  import { getDefaultReporter } from './getDefaultReporter';
5
+ import { getLogger } from './getLogger';
5
6
  import { store } from './store';
6
7
  export const config = function config(options = {}) {
7
- if (store.value.configured && store.value.mode === 'production') {
8
- throw new ProhibitedDuringProduction('config');
8
+ if (store.value.configured) {
9
+ if (store.value.mode === 'production') {
10
+ throw new ProhibitedDuringProduction('config');
11
+ }
12
+ if (store.value.mode === 'test') {
13
+ const log = getLogger('standard-log');
14
+ log.warn(`already configured for test, ignoring config() call`);
15
+ return;
16
+ }
9
17
  }
10
18
  if (options.mode)
11
19
  store.value.mode = options.mode;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAU/B,MAAM,CAAC,MAAM,MAAM,GAA6E,SAAS,MAAM,CAAC,UAAkC,EAAE;IAClJ,IAAI,KAAK,CAAC,KAAK,CAAC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EAAE;YAC3B,iBAAiB,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;KACH;IAED,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAA;IACnE,KAAK,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAA;IAE7B,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;QACrC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;KAClF;SACI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE;QAC3C,OAAO,CAAC,IAAI,CAAC,kFAAkF,CAAC,CAAA;KACjG;AACH,CAAQ,CAAA;AAER,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE;IACxC;;OAEG;IACH,GAAG;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,UAAU,CAAA;IAC/B,CAAC;CACF,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"configForTest.d.ts","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ;;EAQhD"}
1
+ {"version":3,"file":"configForTest.d.ts","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ;;EAShD"}
@@ -1,6 +1,8 @@
1
1
  import { config } from './config';
2
2
  import { createMemoryLogReporter } from './memory';
3
+ import { store } from './store';
3
4
  export function configForTest(logLevel) {
5
+ store.reset();
4
6
  const reporter = createMemoryLogReporter();
5
7
  config({
6
8
  reporters: [reporter],
@@ -1 +1 @@
1
- {"version":3,"file":"configForTest.js","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAIlD,MAAM,UAAU,aAAa,CAAC,QAAmB;IAC/C,MAAM,QAAQ,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,CAAC;QACL,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,IAAI,EAAE,MAAM;QACZ,QAAQ;KACT,CAAC,CAAA;IACF,OAAO,EAAE,QAAQ,EAAE,CAAA;AACrB,CAAC"}
1
+ {"version":3,"file":"configForTest.js","sourceRoot":"","sources":["../src/configForTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAI/B,MAAM,UAAU,aAAa,CAAC,QAAmB;IAC/C,KAAK,CAAC,KAAK,EAAE,CAAA;IACb,MAAM,QAAQ,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,CAAC;QACL,SAAS,EAAE,CAAC,QAAQ,CAAC;QACrB,IAAI,EAAE,MAAM;QACZ,QAAQ;KACT,CAAC,CAAA;IACF,OAAO,EAAE,QAAQ,EAAE,CAAA;AACrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryLogReporter.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAa,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI7F,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAUvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAIlD;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CA4BjG"}
1
+ {"version":3,"file":"MemoryLogReporter.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAa,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI7F,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAUvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CA4BjG"}
@@ -12,7 +12,11 @@ function createGetLogMessage() {
12
12
  export function toMessageWithLevel(logs) {
13
13
  return logs.map(toInspectLogEntry)
14
14
  .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)
15
- .join('\n');
15
+ .join('\n')
16
+ // if it has more than this log,
17
+ // we assume it is running under tests,
18
+ // and remove this log to simplify testing.
19
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\\n.+/, '');
16
20
  }
17
21
  export function createMemoryLogReporter(options) {
18
22
  const opt = required({ id: 'memory', formatter: (e) => e }, options);
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryLogReporter.js","sourceRoot":"","sources":["../../src/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAc9D,SAAS,mBAAmB;IAC1B,OAAO,SAAS,aAAa;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;aACpC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAC9B,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;SAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC;AAGD,MAAM,UAAU,uBAAuB,CAAC,OAAsC;IAC5E,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC9E,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAA;IAClB,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;I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AAA;QAClC,CAAC;QACD,aAAa,EAAE,mBAAmB,EAAE;QACpC,sBAAsB,KAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;KAClE,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standard-log",
3
- "version": "6.3.0",
3
+ "version": "7.0.1",
4
4
  "description": "The standard log library",
5
5
  "homepage": "https://github.com/unional/standard-log/tree/master/packages/log",
6
6
  "bugs": {
@@ -56,6 +56,5 @@
56
56
  },
57
57
  "peerDependencies": {
58
58
  "global-store": "1.0.0-beta.19"
59
- },
60
- "gitHead": "1f2e4c2446729a9860b1c445a3b6c77d428e8fca"
59
+ }
61
60
  }
@@ -1,5 +1,9 @@
1
1
  import a from 'assertron'
2
- import { config, createMemoryLogReporter, logLevels, ProhibitedDuringProduction, toLogLevelName } from '.'
2
+ import {
3
+ config, createMemoryLogReporter,
4
+ logLevels, ProhibitedDuringProduction, toLogLevelName
5
+ } from '.'
6
+ import { configForTest } from './configForTest'
3
7
  import { store } from './store'
4
8
 
5
9
  beforeEach(() => store.reset())
@@ -15,9 +19,7 @@ test('default logLevel is info', () => {
15
19
  })
16
20
 
17
21
  test('configure default logLevel', () => {
18
- config({
19
- logLevel: logLevels.planck
20
- })
22
+ config({ logLevel: logLevels.planck })
21
23
 
22
24
  expect(store.value.logLevel).toBe(logLevels.planck)
23
25
  })
@@ -27,6 +29,12 @@ test('calling config twice throws ProhibitedDuringProduction in production mode'
27
29
  a.throws(() => config({ mode: 'development' }), ProhibitedDuringProduction)
28
30
  })
29
31
 
32
+ test('calling config twice in test mode is allowed, but emit a warning', () => {
33
+ const { reporter } = configForTest()
34
+ config({ mode: 'production' })
35
+ expect(reporter.getLogMessageWithLevel()).toEqual('(WARN) already configured for test, ignoring config() call')
36
+ })
37
+
30
38
  test('add custom levels', () => {
31
39
  config({
32
40
  customLevels: {
package/src/config.ts CHANGED
@@ -2,6 +2,7 @@ import { forEachKey } from 'type-plus'
2
2
  import { addCustomLogLevel } from './customLogLevel'
3
3
  import { ProhibitedDuringProduction } from './errors'
4
4
  import { getDefaultReporter } from './getDefaultReporter'
5
+ import { getLogger } from './getLogger'
5
6
  import { store } from './store'
6
7
  import { LogMode, LogReporter } from './types'
7
8
 
@@ -13,8 +14,15 @@ export type ConfigOptions = {
13
14
  }
14
15
 
15
16
  export const config: { (options?: Partial<ConfigOptions>): void, readonly isLocked: boolean } = function config(options: Partial<ConfigOptions> = {}) {
16
- if (store.value.configured && store.value.mode === 'production') {
17
- throw new ProhibitedDuringProduction('config')
17
+ if (store.value.configured) {
18
+ if (store.value.mode === 'production') {
19
+ throw new ProhibitedDuringProduction('config')
20
+ }
21
+ if (store.value.mode === 'test') {
22
+ const log = getLogger('standard-log')
23
+ log.warn(`already configured for test, ignoring config() call`)
24
+ return
25
+ }
18
26
  }
19
27
 
20
28
  if (options.mode) store.value.mode = options.mode
@@ -1,9 +1,11 @@
1
1
  import { config } from './config'
2
2
  import { createMemoryLogReporter } from './memory'
3
+ import { store } from './store'
3
4
  import { LogLevel } from './types'
4
5
 
5
6
 
6
7
  export function configForTest(logLevel?: LogLevel) {
8
+ store.reset()
7
9
  const reporter = createMemoryLogReporter()
8
10
  config({
9
11
  reporters: [reporter],
@@ -1,177 +1,185 @@
1
- import a from 'assertron';
2
- import { addCustomLogLevel, clearCustomLogLevel, ConsoleLogFormatter, createConsoleLogReporter, LogFilter, logLevels, plainLogFormatter } from '..';
3
- import { config } from '../config';
4
- import { ProhibitedDuringProduction } from '../errors';
5
- import { store } from '../store';
6
-
7
- beforeEach(() => {
8
- store.reset()
9
- config({ mode: 'test' })
10
- })
1
+ import a from 'assertron'
2
+ import {
3
+ addCustomLogLevel, clearCustomLogLevel, config, configForTest,
4
+ ConsoleLogFormatter, createConsoleLogReporter,
5
+ LogFilter, logLevels, plainLogFormatter, ProhibitedDuringProduction
6
+ } from '..'
7
+ import { store } from '../store'
11
8
 
12
- describe('rendering tests', () => {
13
- test('plain rendering', () => {
14
- const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });
15
- ['emergency', 'info', 'warn', 'debug'].forEach(level => {
16
- reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })
17
- })
18
- })
19
- })
9
+ describe('production checks', () => {
10
+ beforeEach(() => store.reset())
20
11
 
21
- describe('id', () => {
22
- test('default is "console"', () => {
12
+ test('set filter during production mode throws', () => {
13
+ config({ mode: 'production' })
23
14
  const reporter = createConsoleLogReporter()
24
- expect(reporter.id).toBe('console')
15
+ a.throws(() => { reporter.filter = () => true }, ProhibitedDuringProduction)
25
16
  })
26
- test('can be overridden', () => {
27
- const reporter = createConsoleLogReporter({ id: 'neo-console' })
28
- expect(reporter.id).toBe('neo-console')
17
+
18
+ const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]
19
+ test('set formatter during production mode throws', () => {
20
+ config({ mode: 'production' })
21
+ const reporter = createConsoleLogReporter()
22
+ a.throws(() => reporter.formatter = idFormatter, ProhibitedDuringProduction)
29
23
  })
30
24
  })
31
25
 
32
- describe('log level', () => {
33
- test('error, alert, critical and emergency logs are written to console.error', () => {
34
- const id = 'log'
35
- const reporter = createConsoleLogReporter()
36
- const fakeConsole = reporter.console = createFakeConsole();
37
26
 
38
- reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
39
- reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })
40
- reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })
41
- reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })
27
+ describe('unit tests', () => {
28
+ beforeEach(() => configForTest())
42
29
 
43
- expect(fakeConsole.errors.length).toBe(4)
30
+ describe('rendering tests', () => {
31
+ test('plain rendering', () => {
32
+ const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });
33
+ ['emergency', 'info', 'warn', 'debug'].forEach(level => {
34
+ reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })
35
+ })
36
+ })
44
37
  })
45
38
 
46
- test('warn logs are written to console.warn', () => {
47
- const id = 'log'
48
- const reporter = createConsoleLogReporter()
49
-
50
- const fakeConsole = reporter.console = createFakeConsole();
39
+ describe('id', () => {
40
+ test('default is "console"', () => {
41
+ const reporter = createConsoleLogReporter()
42
+ expect(reporter.id).toBe('console')
43
+ })
44
+ test('can be overridden', () => {
45
+ const reporter = createConsoleLogReporter({ id: 'neo-console' })
46
+ expect(reporter.id).toBe('neo-console')
47
+ })
48
+ })
51
49
 
52
- reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })
50
+ describe('log level', () => {
51
+ test('error, alert, critical and emergency logs are written to console.error', () => {
52
+ const id = 'log'
53
+ const reporter = createConsoleLogReporter()
54
+ const fakeConsole = reporter.console = createFakeConsole()
53
55
 
54
- expect(fakeConsole.warns.length).toBe(1)
55
- })
56
+ reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
57
+ reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })
58
+ reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })
59
+ reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })
56
60
 
57
- test('notice and info logs are written to console.info', () => {
58
- const id = 'log'
59
- const reporter = createConsoleLogReporter()
61
+ expect(fakeConsole.errors.length).toBe(4)
62
+ })
60
63
 
61
- const fakeConsole = reporter.console = createFakeConsole();
64
+ test('warn logs are written to console.warn', () => {
65
+ const id = 'log'
66
+ const reporter = createConsoleLogReporter()
62
67
 
63
- reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })
64
- reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })
68
+ const fakeConsole = reporter.console = createFakeConsole()
65
69
 
66
- expect(fakeConsole.infos.length).toBe(2)
67
- })
70
+ reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })
68
71
 
72
+ expect(fakeConsole.warns.length).toBe(1)
73
+ })
69
74
 
70
- test('debug, trace, and planck logs are written to console.debug', () => {
71
- const id = 'log'
72
- const reporter = createConsoleLogReporter()
73
- const fakeConsole = reporter.console = createFakeConsole();
75
+ test('notice and info logs are written to console.info', () => {
76
+ const id = 'log'
77
+ const reporter = createConsoleLogReporter()
74
78
 
75
- reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })
76
- reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })
77
- reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })
79
+ const fakeConsole = reporter.console = createFakeConsole()
78
80
 
79
- expect(fakeConsole.debugs.length).toBe(3)
80
- })
81
- })
81
+ reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })
82
+ reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })
82
83
 
83
- describe('custom logs', () => {
84
- afterEach(() => clearCustomLogLevel())
84
+ expect(fakeConsole.infos.length).toBe(2)
85
+ })
85
86
 
86
- test('are written according to their log level value', () => {
87
- addCustomLogLevel('high', 50)
88
- addCustomLogLevel('important', 450)
89
- addCustomLogLevel('interest', 650)
90
- addCustomLogLevel('silly', 1000)
91
87
 
92
- const id = 'log'
93
- const reporter = createConsoleLogReporter()
94
- const fakeConsole = reporter.console = createFakeConsole();
88
+ test('debug, trace, and planck logs are written to console.debug', () => {
89
+ const id = 'log'
90
+ const reporter = createConsoleLogReporter()
91
+ const fakeConsole = reporter.console = createFakeConsole()
95
92
 
96
- reporter.write({ id, level: 50, args: ['a'], timestamp: new Date() })
97
- reporter.write({ id, level: 450, args: ['b'], timestamp: new Date() })
98
- reporter.write({ id, level: 650, args: ['c'], timestamp: new Date() })
99
- reporter.write({ id, level: 1000, args: ['d'], timestamp: new Date() })
93
+ reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })
94
+ reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })
95
+ reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })
100
96
 
101
- expect(fakeConsole.errors.length).toBe(1)
102
- expect(fakeConsole.warns.length).toBe(1)
103
- expect(fakeConsole.infos.length).toBe(1)
104
- expect(fakeConsole.debugs.length).toBe(1)
97
+ expect(fakeConsole.debugs.length).toBe(3)
98
+ })
105
99
  })
106
- })
107
100
 
108
- const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]
101
+ describe('custom logs', () => {
102
+ afterEach(() => clearCustomLogLevel())
109
103
 
110
- describe('formatter', () => {
111
- test('use specific formatter', () => {
112
- const id = 'id-only'
113
- const reporter = createConsoleLogReporter({ formatter: idFormatter })
114
- const fakeConsole = reporter.console = createFakeConsole();
104
+ test('are written according to their log level value', () => {
105
+ addCustomLogLevel('high', 50)
106
+ addCustomLogLevel('important', 450)
107
+ addCustomLogLevel('interest', 650)
108
+ addCustomLogLevel('silly', 1000)
115
109
 
116
- reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
110
+ const id = 'log'
111
+ const reporter = createConsoleLogReporter()
112
+ const fakeConsole = reporter.console = createFakeConsole()
117
113
 
118
- expect(fakeConsole.errors).toEqual([['id-only']])
119
- })
114
+ reporter.write({ id, level: 50, args: ['a'], timestamp: new Date() })
115
+ reporter.write({ id, level: 450, args: ['b'], timestamp: new Date() })
116
+ reporter.write({ id, level: 650, args: ['c'], timestamp: new Date() })
117
+ reporter.write({ id, level: 1000, args: ['d'], timestamp: new Date() })
120
118
 
121
- test('formatter can be changed afterward', () => {
122
- const reporter = createConsoleLogReporter()
123
- const formatter = reporter.formatter
124
- reporter.formatter = idFormatter
125
- expect(reporter.formatter).not.toEqual(formatter)
119
+ expect(fakeConsole.errors.length).toBe(1)
120
+ expect(fakeConsole.warns.length).toBe(1)
121
+ expect(fakeConsole.infos.length).toBe(1)
122
+ expect(fakeConsole.debugs.length).toBe(1)
123
+ })
126
124
  })
127
125
 
128
- test('set formatter during production mode throws', () => {
129
- config({ mode: 'production' })
130
- const reporter = createConsoleLogReporter()
131
- a.throws(() => reporter.formatter = idFormatter, ProhibitedDuringProduction)
132
- })
133
- })
126
+ const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]
134
127
 
135
- describe('filter', () => {
136
- const filter: LogFilter = (entry) => entry.id !== 'secret'
137
- test('use specific filter', () => {
138
- const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })
139
- const fakeConsole = reporter.console = createFakeConsole();
128
+ describe('formatter', () => {
129
+ test('use specific formatter', () => {
130
+ const id = 'id-only'
131
+ const reporter = createConsoleLogReporter({ formatter: idFormatter })
132
+ const fakeConsole = reporter.console = createFakeConsole()
140
133
 
141
- reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
142
- reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
134
+ reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
143
135
 
144
- expect(fakeConsole.errors).toEqual([['normal']])
145
- })
136
+ expect(fakeConsole.errors).toEqual([['id-only']])
137
+ })
146
138
 
147
- test('can change filter', () => {
148
- const reporter = createConsoleLogReporter()
149
- const filter = reporter.filter
150
- reporter.filter = entry => entry.id !== 'secret'
151
- expect(reporter.filter).not.toEqual(filter)
139
+ test('formatter can be changed afterward', () => {
140
+ const reporter = createConsoleLogReporter()
141
+ const formatter = reporter.formatter
142
+ reporter.formatter = idFormatter
143
+ expect(reporter.formatter).not.toEqual(formatter)
144
+ })
152
145
  })
153
146
 
154
- test('set filter during production mode throws', () => {
155
- config({ mode: 'production' })
156
- const reporter = createConsoleLogReporter()
157
- a.throws(() => { reporter.filter = () => true }, ProhibitedDuringProduction)
147
+ describe('filter', () => {
148
+ const filter: LogFilter = (entry) => entry.id !== 'secret'
149
+ test('use specific filter', () => {
150
+ const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })
151
+ const fakeConsole = reporter.console = createFakeConsole()
152
+
153
+ reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
154
+ reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })
155
+
156
+ expect(fakeConsole.errors).toEqual([['normal']])
157
+ })
158
+
159
+ test('can change filter', () => {
160
+ const reporter = createConsoleLogReporter()
161
+ const filter = reporter.filter
162
+ reporter.filter = entry => entry.id !== 'secret'
163
+ expect(reporter.filter).not.toEqual(filter)
164
+ })
158
165
  })
159
- })
160
166
 
161
- test('write log entry with multiple arguments', () => {
162
- const id = 'log'
163
- const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })
164
- const fakeConsole = reporter.console = createFakeConsole();
167
+ test('write log entry with multiple arguments', () => {
168
+ const id = 'log'
169
+ const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })
170
+ const fakeConsole = reporter.console = createFakeConsole()
165
171
 
166
- const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }
172
+ const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }
167
173
 
168
- reporter.write(entry)
174
+ reporter.write(entry)
169
175
 
170
- expect(fakeConsole.infos).toEqual([
171
- [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']
172
- ])
176
+ expect(fakeConsole.infos).toEqual([
177
+ [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']
178
+ ])
179
+ })
173
180
  })
174
181
 
182
+
175
183
  function createFakeConsole() {
176
184
  const errors: any[] = []
177
185
  const infos: any[] = []