[Pkg-javascript-commits] [node-ain2] 57/102: Imported Upstream version 1.0.0
Jonas Smedegaard
js at moszumanska.debian.org
Tue Apr 29 11:59:49 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-ain2.
commit 85a2a30b44ba21c7bf093683d129e8b73930aa0c
Author: Jonas Smedegaard <dr at jones.dk>
Date: Thu Jan 19 12:36:26 2012 +0100
Imported Upstream version 1.0.0
---
CHANGELOG.md | 13 ++++++++++++
index.js | 31 +++++++++++++++--------------
package.json | 4 ++--
readme.md | 65 ++++++++++++++++++++++++++++++------------------------------
4 files changed, 63 insertions(+), 50 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 25b1581..3093edf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
# CHANGELOG
+## v1.0.0
+
+WARNING: This upgrade is not API compatible to previous version.
+
+* Change the API to actually use JavaScript's new operator to create loggers
+
+ var SysLogger = require('ain2');
+ var logger = new SysLogger({ port : 514, tag : 'myTag' });
+
+* If you want to have singleton logger, use
+
+ var logger = require('ain2').getInstance();
+
## v0.2.1
* Support for node v0.6.0 (Yoji Shidara/darashi)
diff --git a/index.js b/index.js
index 122e36b..e507928 100644
--- a/index.js
+++ b/index.js
@@ -4,7 +4,7 @@ var nodeConsole = console;
var DefaultHostname = require("os").hostname();
var DefaultAddress = "127.0.0.1";
-
+var SingletonInstance = null;
function leadZero(n) {
if (n < 10) {
@@ -167,16 +167,29 @@ function format(f) {
* @constructor
* @returns {SysLogger}
*/
-function SysLogger() {
+function SysLogger(config) {
this._times = {};
this._logError = function(err, other) {
if(err){
nodeConsole.error('Cannot log message via %s:%d', this.hostname, this.port);
}
}.bind(this);
+ this.set(config);
+ return this;
}
/**
+* Get singleton instance of SysLogger.
+* @returns {SysLogger}
+*/
+SysLogger.getInstance = function() {
+ if(!SingletonInstance){
+ SingletonInstance = new SysLogger();
+ }
+ return SingletonInstance;
+};
+
+/**
* Init function, takes a configuration object. If a hostname is provided the transport is assumed
* to be Transport.UDP
* @param {Object} configuration object with the following keys:
@@ -237,16 +250,6 @@ SysLogger.prototype.setPort = function(port) {
};
/**
- * Get new instance of SysLogger. All arguments is similar as `set`
- * @returns {SysLogger}
- */
-SysLogger.prototype.get = function() {
- var newLogger = new SysLogger();
- newLogger.set.apply(newLogger, arguments);
- return newLogger;
-};
-
-/**
* Send message
* @param {String} message
* @param {Severity} severity
@@ -330,6 +333,4 @@ SysLogger.prototype.assert = function(expression) {
}
};
-var logger = new SysLogger();
-logger.set();
-module.exports = logger;
+module.exports = SysLogger;
diff --git a/package.json b/package.json
index 26236c6..4f2407e 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name" : "ain2",
"description" : "Syslog logging for node.js. Continuation of ain",
- "version" : "0.2.1",
+ "version" : "1.0.0",
"main" : "./index",
"author" : "Alexander Dorofeev <aka.spin at gmail.com>",
"contributors" : [
@@ -27,7 +27,7 @@
"url" : "http://github.com/phuesler/ain.git"
},
"bugs" : {
- "web" : "http://github.com/phuesler/ain/issues"
+ "url" : "http://github.com/phuesler/ain/issues"
},
"licenses" : [
{
diff --git a/readme.md b/readme.md
index 20f64a5..b212471 100644
--- a/readme.md
+++ b/readme.md
@@ -4,7 +4,7 @@
Brain-free [syslog](http://en.wikipedia.org/wiki/Syslog)** logging for
[node.js](http://nodejs.org).
-*Ain* written with full compatibility with *node.js* `console` module. It
+*Ain* is written with full compatibility with *node.js* `console` module. It
implements all `console` functions and formatting. Also *ain* supports UTF-8
(tested on Debian Testing/Sid).
@@ -20,17 +20,18 @@ systems and logging daemons settings and paths may differ.
## Installation
-You can install *ain* as usual - by copy "ain" directory in your
+You can install *ain* as usual - by copy the "ain" directory in your
`~/.node_modules` or via *npm*
npm install ain2
## Usage
-Usage of *ain* is very similar to *node.js* console. Following example
+Usage of *ain* is very similar to the *node.js* console. The following example
demonstrates the replacement of the console:
- var console = require('ain2');
+ var SysLogger = require('ain2');
+ var console = new SysLogger();
console.log('notice: %d', Date.now());
console.info('info');
@@ -41,6 +42,23 @@ After launch in `/var/log/user` you can see the following:
Dec 5 06:45:26 localhost ex.js[6041]: notice: 1291513526013
Dec 5 06:45:26 localhost ex.js[6041]: info
Dec 5 06:45:26 localhost ex.js[6041]: error
+
+## Singleton logger
+
+If you want to have a singleton that points to the same object whenever you do a require, use the following:
+
+ require('ain2').getInstance();
+
+If you use this, please be beware of this:
+
+ require('ain2').getInstance() === require('ain2').getInstance();
+ => true
+
+As opposed to:
+
+ var SysLogger = require('ain2');
+ new SysLogger() === new SysLogger();
+ => false
## Changing destinations
@@ -52,17 +70,19 @@ By default *ain* sets following destinations:
* `PORT` - 514
* `Transport` - UDP or Unix socket
-You can change them by `set` function. `set` function is chainable.
+You can change them by passing in the params to the constructor or by
+using the `set` function. The `set` function is chainable.
+
+ var SysLogger = require('ain2');
+ var logger = new SysLogger({tag: 'node-test-app', facility: 'daemon', hostname: 'devhost', port: 3000});
- var logger = require('ain2')
- .set({tag: 'node-test-app', facility: 'daemon', hostname: 'devhost', port: 3000});
logger.warn('some warning');
... and in `/var/log/daemon.log`:
Dec 5 07:08:58 devhost node-test-app[10045]: some warning
-`set` function takes one argument, a configuration object which can contain the following keys:
+The `set` function takes one argument, a configuration object which can contain the following keys:
* tag - defaults to __filename
* facility - defaults to user
* hostname - defaults to require('os').hostname()
@@ -97,7 +117,7 @@ your messages.
22 local6 local use 6
23 local7 local use 7
-You can set `facility` by `String` or `Number`:
+You can set the `facility` by `String` or `Number`:
logger.set({tag: 'node-test-app', facility: 3});
logger.set({tag: 'node-test-app', facility: 'daemon'});
@@ -140,30 +160,9 @@ logs messages with different severity levels:
* `trace` - err (3)
* `assert` - err (3)
-To log message with desired severity level you can use `send` function:
+To log a message with the desired severity level you can use the `send` function:
logger.send('message', 'alert');
-`send` function takes two arguments: message and optional severity level. By
-default, severity level is *notice*.
-
-## Additional loggers
-
-After importing *ain* already has default logger. Everything that was
-described above - just about it.
-
-If you need log message with different `TAG`, `facility` and `HOSTNAME`
-without touching default logger, you can get independent instance of logger
-by `get` function.
-
- var logger = require('ain').set('node-test-app', 'daemon', 'devhost');
- logger.warn('some warning');
-
- var anotherLogger = logger.get(logger.tag, 'local0', logger.hostname);
- anotherLogger.log('another messgage');
-
-`get` function takes three arguments - as well as `set` function and return
-new logger object. This object is just new instance of "logger" and has all
-*ain* functions (including `get`).
-
-
+The `send` function takes two arguments: message and optional severity level. By
+default, the severity level is *notice*.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ain2.git
More information about the Pkg-javascript-commits
mailing list