[Pkg-javascript-commits] [node-ain2] 55/102: version v1.0.0 with API that is NOT backwards compatible

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 ef9a5ff5bb5ac957accadd702446b2d379a1ef5d
Author: Patrick Huesler <patrick.huesler at gmail.com>
Date:   Mon Jan 2 17:38:21 2012 +0100

    version v1.0.0 with API that is NOT backwards compatible
---
 CHANGELOG.md | 13 +++++++++++++
 index.js     | 13 ++++++++++++-
 package.json |  2 +-
 readme.md    | 17 +++++++++++++++++
 4 files changed, 43 insertions(+), 2 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 b376da3..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) {
@@ -179,6 +179,17 @@ function SysLogger(config) {
 }
 
 /**
+* 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:
diff --git a/package.json b/package.json
index 1344216..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" : [
diff --git a/readme.md b/readme.md
index cc72184..b212471 100644
--- a/readme.md
+++ b/readme.md
@@ -42,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
 

-- 
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