Skip to content

Commit

Permalink
review logger , add log4js configure
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasyni committed Apr 25, 2014
1 parent 2dcac5e commit 7cebb6e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
13 changes: 13 additions & 0 deletions examples/placeholder/config/log4js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"appenders": [{
"type": "console"
}],

"levels": {

},

"replaceConsole": false,

"lineDebug": true
}
2 changes: 1 addition & 1 deletion lib/beans/beanFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* MIT Licensed
*/

var logger = require('pomelo-logger').getLogger('bearcar', 'BeanFactory');
var logger = require('pomelo-logger').getLogger('bearcat', 'BeanFactory');
var DynamicMetaProxy = require('../aop/framework/dynamicMetaProxy');
var SingletonBeanFactory = require('./singletonBeanFactory');
var BeanDefinition = require('./support/beanDefinition');
Expand Down
2 changes: 1 addition & 1 deletion lib/beans/singletonBeanFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* MIT Licensed
*/

var logger = require('pomelo-logger').getLogger('bearcar', 'SingletonBeanFactory');
var logger = require('pomelo-logger').getLogger('bearcat', 'SingletonBeanFactory');

/**
* SingletonBeanFactory constructor function.
Expand Down
2 changes: 1 addition & 1 deletion lib/beans/support/beanDefinitionVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Copyright(c) 2014 fantasyni <[email protected]>
* MIT Licensed
*/
var logger = require('pomelo-logger').getLogger('bearcar', 'BeanDefinitionVisitor');
var logger = require('pomelo-logger').getLogger('bearcat', 'BeanDefinitionVisitor');
var Constant = require('../../util/constant');
var Utils = require('../../util/utils');

Expand Down
2 changes: 1 addition & 1 deletion lib/beans/support/beanWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* MIT Licensed
*/

var logger = require('pomelo-logger').getLogger('bearcar', 'BeanWrapper');
var logger = require('pomelo-logger').getLogger('bearcat', 'BeanWrapper');

var Constant = require('../../util/constant');
var Utils = require('../../util/utils');
Expand Down
2 changes: 1 addition & 1 deletion lib/bearcat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

var ApplicationContext = require('./context/applicationContext');
var logger = require('pomelo-logger').getLogger('bearcar', 'app');
var logger = require('pomelo-logger').getLogger('bearcat', 'app');
var BeanFactory = require('./beans/beanFactory');
var Utils = require('./util/utils');

Expand Down
28 changes: 26 additions & 2 deletions lib/context/applicationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
* MIT Licensed
*/

var logger = require('pomelo-logger').getLogger('bearcar', 'ApplicationContext');
var logger = require('pomelo-logger').getLogger('bearcat', 'ApplicationContext');
var PlaceHolderConfigurer = require('../beans/support/placeHolderConfigurer');
var AutoProxyCreator = require('../aop/autoproxy/autoProxyCreator');
var ResourceLoader = require('../resource/resourceLoader');
var BeanFactory = require('../beans/beanFactory');
var EventEmitter = require('events').EventEmitter;
var Constant = require('../util/constant');
var Utils = require('../util/utils');
var path = require('path');
var util = require('util');
var DEFAULT_LOAD_PATH = process.cwd() + "/config";
var fs = require('fs');
var DEFAULT_BASE = process.cwd();
var DEFAULT_LOAD_PATH = DEFAULT_BASE + "/config";

/**
* ApplicationContext constructor function.
Expand All @@ -35,6 +38,7 @@ var ApplicationContext = function(configLocations) {
this.resourceLoader = null;
this.cpath = DEFAULT_LOAD_PATH;
this.env = Constant.DEFAULT_ENV;
this.base = DEFAULT_BASE;
this.beanFactoryPostProcessors = [];
EventEmitter.call(this);
}
Expand Down Expand Up @@ -177,6 +181,16 @@ ApplicationContext.prototype.prepareRefresh = function() {
cpath = args.cpath || args['--cpath'] || cpath;

this.setConfigPath(cpath);

var base = this.getBase();
if (process.env.BEARCAT_LOGGER !== 'off') {
var loggerConfigPath = path.join(cpath, Constant.LOGPATH);
if (fs.existsSync(loggerConfigPath)) {
require('pomelo-logger').configure(loggerConfigPath, {
base: base
});
}
}
}

/**
Expand Down Expand Up @@ -529,4 +543,14 @@ ApplicationContext.prototype.setConfigPath = function(cpath) {
*/
ApplicationContext.prototype.getConfigPath = function() {
return this.cpath;
}

/**
* ApplicationContext get base path.
*
* @return {String} base path
* @api public
*/
ApplicationContext.prototype.getBase = function() {
return this.base;
}
4 changes: 3 additions & 1 deletion lib/util/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ module.exports = {

PROXY_DEFAULT: true,

DEFAULT_ENV: "dev"
DEFAULT_ENV: "dev",

LOGPATH: "log4js.json"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bearcat",
"version": "0.1.2",
"version": "0.1.3",
"description": "a POJOs based application framework for node.js",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 7cebb6e

Please sign in to comment.