Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appl

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appl - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

default.js

18

logger.js
'use strict';
var Colored;
var Current;
var Logger;
var logger;
var Styled;
Colored = /** @type Colored */ require('./src/logger/Colored');
Logger = /** @type Logger */ require('./src/logger/Logger');
Current = 'development' === process.env.NODE_ENV ? Colored : Logger;
Styled = require('./src/logger/Styled');
logger = new Current({
ERR: process.stderr,
WRN: process.stderr
});
logger.Logger = Current;
module.exports = logger;
module.exports = new Styled();

@@ -30,6 +30,6 @@ {

"scripts": {
"test": "./tools/test"
"test": "tools/test"
},
"version": "0.0.4",
"readme": "appl [![Build Status](https://travis-ci.org/golyshevd/Logger.png?branch=v0.0.x)](https://travis-ci.org/golyshevd/Logger)\n=========\nsimple funny extensible logger\n\n![Demo](https://raw.github.com/golyshevd/Logger/master/stuff/2013-12-17_1757.png)\n"
"version": "1.0.0",
"readme": "appl [![Build Status](https://travis-ci.org/golyshevd/Logger.png?branch=v1.0.x)](https://travis-ci.org/golyshevd/Logger)\n=========\nsimple funny extensible logger\n\n![Demo](https://raw.github.com/golyshevd/Logger/master/stuff/2013-12-17_1757.png)\n"
}
'use strict';
var Util;
var extend;
var hasProperty;
Util = require('util');
extend = require('../lang/extend');
hasProperty = Object.prototype.hasOwnProperty;
/**
* @abstract
* @class Logger
* */
function Logger (streams) {
function Logger () {
var level;
/**
* @public
* @memberOf {Logger}
* @property process.stdout
* */
this.stream = process.stdout;
/**
* @protected
* @memberOf {Logger}
* @property {Object}
* */
this._streams = {};
this.levels = {
DBG: {
weight: 0,
stream: process.stdout
},
INF: {
weight: 1,
stream: process.stdout
},
LOG: {
weight: 2,
stream: process.stdout
},
WRN: {
weight: 3,
stream: process.stderr
},
ERR: {
weight: 4,
stream: process.stderr
},
FTL: {
weight: 5,
stream: process.stderr
}
};
for ( level in streams ) {
if ( hasProperty.call(streams, level) ) {
this._streams[level] = streams[level];
}
}
}

@@ -41,7 +56,7 @@

/**
* @protected
* @public
* @memberOf {Logger}
* @method
* @property {Number}
* */
constructor: Logger,
logLevel: 0,

@@ -54,3 +69,3 @@ /**

debug: function () {
this.write('DBG', arguments);
this._write('DBG', arguments, this._defaultFormat);
},

@@ -62,25 +77,5 @@

* @method
*
* @param {*} o
* */
dir: function (o) {
this.write('DBG', [Util.inspect(o)]);
},
/**
* @public
* @memberOf {Logger}
* @method
* */
error: function () {
this.write('ERR', arguments);
},
/**
* @public
* @memberOf {Logger}
* @method
* */
info: function () {
this.write('INF', arguments);
this._write('INF', arguments, this._defaultFormat);
},

@@ -94,3 +89,3 @@

log: function () {
this.write('LOG', arguments);
this._write('LOG', arguments, this._defaultFormat);
},

@@ -103,9 +98,4 @@

* */
trace: function () {
var trace;
trace = (new Error()).stack.split('\n').slice(2).join('\n');
trace = this._format('ERR', arguments) + trace + '\n';
this._getStream('ERR').write(trace);
warn: function () {
this._write('WRN', arguments, this._defaultFormat);
},

@@ -118,16 +108,8 @@

* */
warn: function () {
this.write('WRN', arguments);
error: function () {
this._write('ERR', arguments, this._defaultFormat);
},
/**
* @public
* @memberOf {Logger}
* @method
*
* @param {String} level
* @param {Array|Arguments} args
* */
write: function (level, args) {
this._getStream(level).write(this._format(level, args));
fatal: function () {
this._write('FTL', arguments, this._defaultFormat);
},

@@ -139,9 +121,8 @@

* @method
*
* @returns {Stream.Writable}
* */
_getStream: function (level) {
constructor: Logger,
return hasProperty.call(this._streams, level) ?
this._streams[level] : this.stream;
_defaultFormat: function (buf) {
return Util.format.apply(Util, buf);
},

@@ -154,36 +135,12 @@

*
* @param {Date} ts
* @param {*} level
* @param {Array} buf
* @param {Function} theme
*
* @returns {String}
* */
_formatTime: function (ts) {
_format: function (level, buf, theme) {
var ofs;
ofs = ts.getTimezoneOffset() / 60;
if ( ofs < 0 ) {
if ( ofs > -10 ) {
ofs = '0' + ( -ofs );
}
ofs = '+' + ( ofs ) + '00';
} else {
if ( ofs < 10 ) {
ofs = '0' + ofs;
}
ofs = '-' + ofs + '00';
}
return Logger.__addZero__( ts.getDate() ) +
'/' + Logger.__months__[ ts.getMonth() ] +
'/' + ts.getFullYear() +
':' + Logger.__addZero__( ts.getHours() ) +
':' + Logger.__addZero__( ts.getMinutes() ) +
':' + Logger.__addZero__( ts.getSeconds() ) +
' ' + ofs;
return this._formatHead(level) + ': ' +
theme.call(this, buf);
},

@@ -196,11 +153,9 @@

*
* @param {String} level
* @param {Array} [args]
* @param {Number} level
*
* @returns {String}
* */
_format: function (level, args) {
_formatHead: function (level) {
return this._formatHeader(level) + ': ' +
this._formatMessage(args) + '\n';
return this._formatDate(new Date()) + ' ' + this._formatLevel(level);
},

@@ -213,10 +168,9 @@

*
* @param {String} level
* @param {Date} ts
*
* @returns {String}
* */
_formatHeader: function (level) {
return '[' + this._formatTime(this._getTime()) + '] ' +
this._formatLevel(level) + ' ' +
this._formatPid(this._getPid());
_formatDate: function (ts) {
return String(ts);
},

@@ -229,3 +183,3 @@

*
* @param {String} level
* @param {*} level
*

@@ -244,45 +198,20 @@ * @returns {String}

*
* @param {Number} pid
*
* @returns {String}
* @param {String} level
* @param {Array} buf
* @param {Function} theme
* */
_formatPid: function (pid) {
_write: function (level, buf, theme) {
return String(pid);
},
var descr;
/**
* @protected
* @memberOf {Logger}
* @method
*
* @returns {Number}
* */
_getPid: function () {
descr = this.levels[level];
return process.pid;
},
// иначе проверяем есть ли доступ к логгированию
if ( descr.weight < this.logLevel ) {
/**
* @protected
* @memberOf {Logger}
* @method
*
* @returns {Date}
* */
_getTime: function () {
return;
}
return new Date();
},
/**
* @protected
* @memberOf {Logger}
* @method
*
* @returns {String}
* */
_formatMessage: function (args) {
return Util.format.apply(Util, args);
// записываем строку в поток
descr.stream.write(this._format(level, buf, theme) + '\n');
}

@@ -292,38 +221,2 @@

/**
* @private
* @static
* @memberOf {Logger}
*
* @param {Number} n
*
* @returns {String}
* */
Logger.__addZero__ = function (n) {
return n < 10 ? '0' + n : n;
};
/**
* @private
* @static
* @memberOf Logger
*
* @property {Array<String>}
* */
Logger.__months__ = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
];
module.exports = Logger;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc