Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bimedia-fr/architect-log4js
log4js architect plugin
https://github.com/bimedia-fr/architect-log4js
Last synced: 2 months ago
JSON representation
log4js architect plugin
- Host: GitHub
- URL: https://github.com/bimedia-fr/architect-log4js
- Owner: bimedia-fr
- License: apache-2.0
- Created: 2014-03-17T21:09:46.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-09-26T16:04:15.000Z (over 1 year ago)
- Last Synced: 2024-11-02T20:03:22.035Z (3 months ago)
- Language: JavaScript
- Size: 228 KB
- Stars: 2
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
architect-log4js
================Expose [log4js](https://github.com/nomiddlename/log4js-node) as architect service.
### Installation
```sh
npm install --save architect-log4js
```
### Config Format
```js
{
"packagePath": "architect-log4js",
"config": {
appenders: {
out: { type: 'console' }
},
categories: {
default: { appenders: [ 'out' ], level: 'info' }
}
}
}}
```### Usage
Boot [Architect](https://github.com/c9/architect) :
```js
var path = require('path');
var architect = require("architect");var configPath = path.join(__dirname, "config.js");
var config = architect.loadConfig(configPath);architect.createApp(config, function (err, app) {
if (err) {
throw err;
}
//app.services.log is avaliable now
var log = app.services.log.getLogger('app');
log.info('application started');
});
```Configure Log4js Architect service with `config.js` :
```js
module.exports = [{
packagePath: "architect-log4js",
config: {
appenders: [
{ type: "console" }
],
replaceConsole: true
}
}, './routes'];
```
`config` object is passed to `log4js.configure` method. See [log4js configuration](https://github.com/nomiddlename/log4js-node#configuration) for more options.Consume *log* service in your application :
```js
{
"name": "routes",
"version": "0.0.1",
"main": "index.js",
"private": true,"plugin": {
"consumes": ["log"]
}
}
```Eventually use the `log` service in your app :
```js
module.exports = function setup(options, imports, register) {
var logger = imports.log.getLogger(); //get default logger
log.info('plugin initialized.');
register();
};
```
### request logger
This module provides a log request feature that is not available in log4js itself.Example :
```js
rest.get('/', function(req, res) {
var logger = imports.log.requestLogger(req).getLogger(); //get default logger
log.info('plugin initialized.');
});
```
This will produce :
```
[2015-02-06 16:03:54.329] [INFO] - [/] plugin initialized.
```
#### options* request.property : request property to log defaults to ```'url'```. May also be a function that takes a request as first argument.
* request.format : {string} message format defaults to ```'[%s] %s'```, where first placeholder is the request property and the second is the actual message.