source: trip-planner-front/node_modules/log4js/lib/configuration.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1
2
3const util = require('util');
4const debug = require('debug')('log4js:configuration');
5
6const preProcessingListeners = [];
7const listeners = [];
8
9const not = thing => !thing;
10
11const anObject = thing => thing && typeof thing === 'object' && !Array.isArray(thing);
12
13const validIdentifier = thing => /^[A-Za-z][A-Za-z0-9_]*$/g.test(thing);
14
15const anInteger = thing => thing && typeof thing === 'number' && Number.isInteger(thing);
16
17const addListener = (fn) => {
18 listeners.push(fn);
19 debug(`Added listener, now ${listeners.length} listeners`);
20};
21
22const addPreProcessingListener = (fn) => {
23 preProcessingListeners.push(fn);
24 debug(`Added pre-processing listener, now ${preProcessingListeners.length} listeners`);
25};
26
27const throwExceptionIf = (config, checks, message) => {
28 const tests = Array.isArray(checks) ? checks : [checks];
29 tests.forEach((test) => {
30 if (test) {
31 throw new Error(`Problem with log4js configuration: (${util.inspect(config, { depth: 5 })})`
32 + ` - ${message}`);
33 }
34 });
35};
36
37const configure = (candidate) => {
38 debug('New configuration to be validated: ', candidate);
39 throwExceptionIf(candidate, not(anObject(candidate)), 'must be an object.');
40
41 debug(`Calling pre-processing listeners (${preProcessingListeners.length})`);
42 preProcessingListeners.forEach(listener => listener(candidate));
43 debug('Configuration pre-processing finished.');
44
45 debug(`Calling configuration listeners (${listeners.length})`);
46 listeners.forEach(listener => listener(candidate));
47 debug('Configuration finished.');
48};
49
50module.exports = {
51 configure,
52 addListener,
53 addPreProcessingListener,
54 throwExceptionIf,
55 anObject,
56 anInteger,
57 validIdentifier,
58 not
59};
Note: See TracBrowser for help on using the repository browser.