Skip to content

Commit

Permalink
Move all files to deprecated folder. Rewrite constants and logger mod…
Browse files Browse the repository at this point in the history
…eule. Implement tests coverage for constants and logger modules
  • Loading branch information
tormozz48 committed Feb 28, 2015
1 parent df4a818 commit 04e33cb
Show file tree
Hide file tree
Showing 63 changed files with 316 additions and 1,601 deletions.
49 changes: 49 additions & 0 deletions .istanbul.yml
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.
5 changes: 4 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var path = require('path');

module.exports = {
DIRECTORY: {
MODEL: 'model'
CACHE: path.join(process.cwd(), 'cache'),
MODEL: path.join(process.cwd(), 'model')
},
GITHUB: {
PRIVATE: 'github.yandex-team.ru',
Expand Down
195 changes: 114 additions & 81 deletions src/logger.js
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;
87 changes: 0 additions & 87 deletions src/model/change-type.js

This file was deleted.

36 changes: 0 additions & 36 deletions src/model/changes.js

This file was deleted.

0 comments on commit 04e33cb

Please sign in to comment.