[Pkg-javascript-commits] [node-ain2] 02/102: typo

Jonas Smedegaard js at moszumanska.debian.org
Tue Apr 29 11:59:44 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 fa894bbc6f0dd9df2582e8a592c0fee4dfbbd085
Author: Alexander Dorofeev <aka.spin at gmail.com>
Date:   Sun Dec 5 06:44:43 2010 +0500

    typo
---
 index.js  | 49 ++++++++++++++++++++++++++++++++++++++++++-------
 readme.md | 22 ++++++++++++++++------
 2 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/index.js b/index.js
index 58eb092..5497776 100644
--- a/index.js
+++ b/index.js
@@ -65,17 +65,26 @@ function format(f) {
   return str;
 }
 
+function leadZero(n) {
+    if (n < 10) {
+        return '0' + n;
+    } else {
+        return n;
+    }
+}
+
 /**
  * Get current date in syslog format. Thanks https://github.com/kordless/lodge
  * @returns {String}
  */
 function getDate() {
     var dt = new Date();
-    var hours = dt.getHours();
-    var minutes = dt.getMinutes();
-    var seconds = dt.getSeconds();
+    var hours = leadZero(dt.getHours());
+    var minutes = leadZero(dt.getMinutes());
+    var seconds = leadZero(dt.getSeconds());
     var month = dt.getMonth();
     var day = dt.getDate();
+    (day < 10) && (day = ' ' + day);
     var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
             'Sep', 'Oct', 'Nov', 'Dec' ];
     return months[month] + " " + day + " " + hours + ":" + minutes
@@ -88,10 +97,11 @@ function getDate() {
  * @returns {SysLogger}
  */
 function SysLogger() {
+    this.times = {};
 }
 /**
  * Init function
- * @param {Facility|Number|String} facility
+ * @param {Facility|Number|String} Optional facility
  * @param {String} name Optional name. By default is process.argv[1]
  * @param {String} hostname Optional hostname. 
  */
@@ -105,8 +115,8 @@ SysLogger.prototype.init = function(facility, name, hostname) {
 };
 /**
  * Get new instance of SysLogger. 
- * @param {Facility|Number|String} facility
  * @param {String} name Optional name. By default is process.argv[1]
+ * @param {Facility|Number|String} facility
  * @param {String} hostname Optional hostname. 
  * @returns {SysLogger}
  */
@@ -122,14 +132,16 @@ SysLogger.prototype.get = function() {
  */
 SysLogger.prototype._send = function(message, severity) {
     var client = dgram.createSocket('udp4');
-    var message = new Buffer('<' + this.facility * 8 + severity + '>' +
+    var message = new Buffer('<' + (this.facility * 8 + severity) + '>' +
         getDate() + ' ' + this.hostname + ' ' + 
         this.name + '[' + process.pid + ']:' + message);
+    console.log('%s', message);
+    
     client.send(message, 0, message.length, 514, '127.0.0.1', 
         function(err) {
             if (err) console.error('Can\'t connect to localhost:514');
-            client.close();
     });
+    client.close();
 };
 
 /**
@@ -161,6 +173,29 @@ SysLogger.prototype.dir = function(object) {
     this._send(util.inspect(object) + '\n', Severity.notice);
 };
 
+SysLogger.prototype.time = function(label) {
+    this.times[label] = Date.now();
+};
+SysLogger.prototype.timeEnd = function(label) {
+    var duration = Date.now() - this.times[label];
+    this.log('%s: %dms', label, duration);
+};
+
+SysLogger.prototype.trace = function(label) {
+    var err = new Error;
+    err.name = 'Trace';
+    err.message = label || '';
+    Error.captureStackTrace(err, arguments.callee);
+    this.error(err.stack);
+};
+
+SysLogger.prototype.assert = function(expression) {
+    if (!expression) {
+        var arr = Array.prototype.slice.call(arguments, 1);
+        this._send(format.apply(this, arr), Severity.err);
+    }
+};
 
 var logger = new SysLogger();
+logger.init();
 module.exports = logger;
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 264aa86..e5b6d19 100644
--- a/readme.md
+++ b/readme.md
@@ -1,19 +1,29 @@
-# ain
+# ain*
 
-Brain-free node.js logger for syslog.
+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 
 implements all `console` functions and formatting. Also *ain* supports UTF-8 
 (tested on Debian Testing/Sid).
 
+*In the Phoenician alphabet letter "ain" indicates eye.
+**All examples tested under Debian Squeeze `rsyslog`. On other operating 
+systems and logging daemons settings and paths may differ.
+
 ## Usage
 
 Usage of *ain* is very similar to *node.js* console. Following example 
 demonstrates the replacement of the console:
 
     var console = require('ain');
-    console.init(logger.LEVEL0, 'node-test-app');
     
-    console.log('notice level by number %d', Date.now());
-    console.info('info level');
-    
\ No newline at end of file
+    console.log('notice severity by number %d', Date.now());
+    console.info('info severity');
+    console.error('error severity');
+    
+After launch in `/var/log/user` you can see the following:
+
+    
+    
+As noticed before *ain* implements all `console` functions.

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