-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all files to deprecated folder. Rewrite constants and logger mod…
…eule. Implement tests coverage for constants and logger modules
- Loading branch information
Showing
63 changed files
with
316 additions
and
1,601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
verbose: false | ||
instrumentation: | ||
root: . | ||
default-excludes: true | ||
excludes: [deprecated_src, deprecated_test] | ||
embed-source: false | ||
variable: __coverage__ | ||
compact: true | ||
preserve-comments: false | ||
complete-copy: false | ||
save-baseline: false | ||
baseline-file: ./coverage/coverage-baseline.json | ||
include-all-sources: false | ||
reporting: | ||
print: summary | ||
reports: | ||
- lcov | ||
dir: ./coverage | ||
watermarks: | ||
statements: [50, 80] | ||
lines: [50, 80] | ||
functions: [50, 80] | ||
branches: [50, 80] | ||
report-config: | ||
clover: {file: clover.xml} | ||
cobertura: {file: cobertura-coverage.xml} | ||
json: {file: coverage-final.json} | ||
json-summary: {file: coverage-summary.json} | ||
lcovonly: {file: lcov.info} | ||
teamcity: {file: null} | ||
text: {file: null, maxCols: 0} | ||
text-summary: {file: null} | ||
hooks: | ||
hook-run-in-context: false | ||
post-require-hook: null | ||
handle-sigint: false | ||
check: | ||
global: | ||
statements: 0 | ||
lines: 0 | ||
branches: 0 | ||
functions: 0 | ||
excludes: [] | ||
each: | ||
statements: 0 | ||
lines: 0 | ||
branches: 0 | ||
functions: 0 | ||
excludes: [] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,128 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'), | ||
path = require('path'), | ||
|
||
_ = require('lodash'), | ||
var _ = require('lodash'), | ||
intel = require('intel'), | ||
baseHandlerConfig = { | ||
|
||
Logger = function (mode, level, options) { | ||
this._init(mode, level, options); | ||
}; | ||
|
||
Logger.prototype = { | ||
|
||
_DEFAULT_LOG_MODE: 'testing', | ||
_DEFAULT_LOG_LEVEL: 'info', | ||
|
||
_mode: undefined, | ||
_level: undefined, | ||
_options: undefined, | ||
|
||
_baseHandlerConfiguration: { | ||
level: intel.VERBOSE, | ||
formatter: new intel.Formatter({ | ||
format: '[%(date)s] %(levelname)s %(name)s: %(message)s', | ||
colorize: true | ||
}) | ||
}, | ||
LOG_DIR = path.join(process.cwd(), 'logs'); | ||
|
||
try { | ||
fs.mkdirSync(LOG_DIR); | ||
}catch (err) { | ||
err; | ||
} | ||
|
||
intel.setLevel('debug'); | ||
intel.addHandler( | ||
new intel.handlers.Console(_.extend({}, baseHandlerConfig)) | ||
); | ||
|
||
/* | ||
intel.addHandler( | ||
new intel.handlers.Rotating(_.extend({ | ||
file: path.join(LOG_DIR, 'bse.log'), | ||
maxSize: 1024 * 1024 | ||
}, baseHandlerConfig)) | ||
); | ||
*/ | ||
|
||
/** | ||
* Returns logger by it name | ||
* If first arguments is module then add part of module file path to log string | ||
* @param {Object} module | ||
* @returns {*} | ||
*/ | ||
function getLogger(module) { | ||
return intel.getLogger(module ? module.filename.split('/').slice(-2).join('/') : ''); | ||
} | ||
|
||
/** | ||
* Alias for logging verbose messages | ||
* @param {String} str (string) for logging | ||
* @param {Object} module object | ||
* @returns {*} | ||
*/ | ||
exports.verbose = function (str, module) { | ||
return getLogger(module).verbose(str); | ||
}; | ||
|
||
/** | ||
* Alias for logging debug messages | ||
* @param {String} str (string) for logging | ||
* @param {Object} module object | ||
* @returns {*} | ||
*/ | ||
exports.debug = function (str, module) { | ||
return getLogger(module).debug(str); | ||
}; | ||
/** | ||
* Logger initialization function | ||
* @param {String} mode - logger mode (development|testing|production) | ||
* @param {String} level - logger level (verbose|debug|info|warn|error) | ||
* @param {Object} options - advanced logger options | ||
* @private | ||
*/ | ||
_init: function (mode, level, options) { | ||
this._mode = mode || this._DEFAULT_LOG_MODE; | ||
this._level = level || this._DEFAULT_LOG_LEVEL; | ||
this._options = options; | ||
|
||
/** | ||
* Alias for logging info messages | ||
* @param {String} str (string) for logging | ||
* @param {Object} module object | ||
* @returns {*} | ||
*/ | ||
exports.info = function (str, module) { | ||
return getLogger(module).info(str); | ||
}; | ||
if (this._mode === 'development') { | ||
intel.setLevel(this._level); | ||
intel.addHandler( | ||
new intel.handlers.Console(_.extend({}, this._baseHandlerConfiguration)) | ||
); | ||
} | ||
}, | ||
|
||
/** | ||
* Alias for logging warn messages | ||
* @param {String} str (string) for logging | ||
* @param {Object} module object | ||
* @returns {*} | ||
*/ | ||
exports.warn = function (str, module) { | ||
return getLogger(module).warn(str); | ||
}; | ||
/** | ||
* Returns logger by current mode and log level | ||
* @returns {Object} logger | ||
* @private | ||
*/ | ||
_getLogger: function () { | ||
var _this = this, | ||
getLFD = function () { | ||
var parent = module.parent; | ||
return intel.getLogger(parent.filename.split('/').slice(-2).join('/')); | ||
}, | ||
getLFT = function () { | ||
return { | ||
verbose: function () {}, | ||
debug: function () {}, | ||
info: function () {}, | ||
warn: console.warn, | ||
error: console.error | ||
}; | ||
}, | ||
getLFP = function () { | ||
return ['verbose', 'debug', 'info', 'warn', 'error'].reduce(function (prev, item, index, arr) { | ||
prev[item] = arr.slice(0, index + 1).indexOf(_this._level) > -1 ? | ||
(console[item] || console.log) : function () {}; | ||
return prev; | ||
}, {}); | ||
}; | ||
|
||
/** | ||
* Alias for logging error messages | ||
* @param {String} str (string) for logging | ||
* @param {Object} module object | ||
* @returns {*} | ||
*/ | ||
exports.error = function (str, module) { | ||
return getLogger(module).error(str); | ||
return { | ||
development: getLFD(), | ||
testing: getLFT(), | ||
production: getLFP() | ||
}[this._mode]; | ||
}, | ||
|
||
/** | ||
* Alias for logging verbose messages | ||
* @param {String} str (string) for logging | ||
* @returns {*} | ||
*/ | ||
verbose: function (str) { | ||
return this._getLogger().verbose(str); | ||
}, | ||
|
||
/** | ||
* Alias for logging debug messages | ||
* @param {String} str (string) for logging | ||
* @returns {*} | ||
*/ | ||
debug: function (str) { | ||
return this._getLogger().debug(str); | ||
}, | ||
|
||
/** | ||
* Alias for logging info messages | ||
* @param {String} str (string) for logging | ||
* @returns {*} | ||
*/ | ||
info: function (str) { | ||
return this._getLogger(module).info(str); | ||
}, | ||
|
||
/** | ||
* Alias for logging warn messages | ||
* @param {String} str (string) for logging | ||
* @returns {*} | ||
*/ | ||
warn: function (str) { | ||
return this._getLogger().warn(str); | ||
}, | ||
|
||
/** | ||
* Alias for logging error messages | ||
* @param {String} str (string) for logging | ||
* @returns {*} | ||
*/ | ||
error: function (str) { | ||
return this._getLogger().error(str); | ||
} | ||
}; | ||
|
||
module.exports = Logger; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.