Skip to content

Commit

Permalink
πŸ“¦ v 2.1.0
Browse files Browse the repository at this point in the history
- πŸ‘¨β€πŸ’» Minor codebase refactoring
- πŸ‘¨β€πŸ”§ Properly sanitize and process `data` log argument; *Potentially* fixing [logger-file #17](veliovgroup/Meteor-logger-file#17)
- πŸ“” Minor documentation improvements
- 🀝 Compatibility with latest `[email protected]`
  • Loading branch information
dr-dimitru committed May 31, 2022
1 parent e197bc6 commit 4b1ce00
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 73 deletions.
75 changes: 38 additions & 37 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
[email protected].0
babel-compiler@7.2.4
babel-runtime@1.3.0
[email protected].11
[email protected].1
babel-compiler@7.9.0
babel-runtime@1.5.0
[email protected].12
[email protected]
boilerplate-generator@1.6.0
callback-hook@1.1.0
boilerplate-generator@1.7.1
callback-hook@1.4.0
[email protected]
[email protected]
ddp-client@2.3.3
ddp-client@2.5.0
[email protected]
ddp-server@2.2.0
ddp-server@2.5.0
[email protected]
dynamic-import@0.5.0
ecmascript@0.12.4
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.8.0
ecmascript-runtime-server@0.7.1
[email protected].0
[email protected].0
dynamic-import@0.7.2
ecmascript@0.16.2
ecmascript-runtime@0.8.0
ecmascript-runtime-client@0.12.1
ecmascript-runtime-server@0.11.0
[email protected].2
[email protected].1
[email protected]
[email protected].0
[email protected].0
local-test:ostrio:logger@2.0.8
logging@1.1.20
meteor@1.9.2
minimongo@1.4.5
[email protected].3
modules@0.13.0
modules-runtime@0.10.3
mongo@1.6.0
[email protected].0
[email protected].1
[email protected].1
local-test:ostrio:logger@2.1.0
logging@1.3.1
meteor@1.10.0
minimongo@1.8.0
[email protected].8
modules@0.18.0
modules-runtime@0.13.0
mongo@1.15.0
[email protected].3
[email protected]
[email protected].7
npm-mongo@3.1.1
[email protected].8
npm-mongo@4.3.1
[email protected]
ostrio:[email protected]
[email protected]
[email protected]
ostrio:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
reload@1.2.0
reload@1.3.1
[email protected]
[email protected].0
socket-stream-client@0.2.2
tinytest@1.1.0
[email protected].1
socket-stream-client@0.5.0
tinytest@1.2.1
[email protected]
[email protected]
webapp@1.7.1
webapp-hashing@1.0.9
webapp@1.13.1
webapp-hashing@1.1.0
74 changes: 39 additions & 35 deletions logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { check, Match } from 'meteor/check';

const helpers = {
Expand Down Expand Up @@ -38,11 +38,33 @@ const helpers = {

const _helpers = ['String', 'Date'];
for (let i = 0; i < _helpers.length; i++) {
helpers['is' + _helpers[i]] = function (obj) {
return Object.prototype.toString.call(obj) === '[object ' + _helpers[i] + ']';
helpers[`is${_helpers[i]}`] = function (obj) {
return Object.prototype.toString.call(obj) === `[object ${_helpers[i]}]`;
};
}

/*
* @class LoggerMessage
* @param data {Object}
* @summary Construct message object, ready to be thrown and stringified
*/
class LoggerMessage {
constructor(data) {
this.data = data.data;
this.user = data.user;
this.level = data.level;
this.error = data.error;
this.userId = data.userId;
this.reason = data.reason;
this.details = data.details;
this.message = data.message;

this.toString = () => {
return `[${this.reason}] \nLevel: ${this.level}; \nDetails: ${JSON.stringify(this.data)}; \nUserId: ${this.userId};`;
};
}
}

let _inst = 0;

/*
Expand All @@ -51,9 +73,9 @@ let _inst = 0;
*/
class Logger {
constructor() {
this.userId = new ReactiveVar(null);
this.prefix = ++_inst;
this._rules = {};
this.userId = new ReactiveVar(null);
this.prefix = ++_inst;
this._rules = {};
this._emitters = [];

if (Meteor.isClient) {
Expand All @@ -75,15 +97,22 @@ class Logger {
* @name _log
* @param level {String} - Log level Accepts 'ERROR', 'FATAL', 'WARN', 'DEBUG', 'INFO', 'TRACE', 'LOG' and '*'
* @param message {String} - Text human-readable message
* @param data {Object} - [optional] Any additional info as object
* @param data {Object|String} - [optional] Any additional info as object
* @param userId {String} - [optional] Current user id
* @summary Pass log's data to Server or/and Client
*/
_log(level, message, _data = {}, user) {
const uid = user || this.userId.get();
let data;

// sanitize circular refs before passing to emitters
let data = Logger.prototype.antiCircular(_data);
if (_data === null || _data === undefined){
data = {};
} else if (helpers.isObject(_data)) {
// sanitize circular refs before passing to emitters
data = Logger.prototype.antiCircular(_data);
} else {
data = { data: helpers.clone( _data) };
}

for (const i in this._emitters) {
if (this._rules[this._emitters[i].name] && this._rules[this._emitters[i].name].enable === true) {
Expand All @@ -93,9 +122,6 @@ class Logger {

if (this._rules[this._emitters[i].name].allow.indexOf('*') !== -1 || this._rules[this._emitters[i].name].allow.indexOf(level) !== -1) {
if (level === 'TRACE') {
if (helpers.isString(data)) {
data = {data: helpers.clone(data)};
}
data.stackTrace = this._getStackTrace();
}

Expand Down Expand Up @@ -311,26 +337,4 @@ class Logger {
}
}

/*
* @class LoggerMessage
* @param data {Object}
* @summary Construct message object, ready to be thrown and stringified
*/
class LoggerMessage {
constructor(data) {
this.data = data.data;
this.user = data.user;
this.level = data.level;
this.error = data.error;
this.userId = data.userId;
this.reason = data.reason;
this.details = data.details;
this.message = data.message;

this.toString = () => {
return `[${this.reason}] \nLevel: ${this.level}; \nDetails: ${JSON.stringify(this.data)}; \nUserId: ${this.userId};`;
};
}
}

export { Logger, LoggerMessage };
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:logger',
version: '2.0.8',
version: '2.1.0',
summary: 'Logging: isomorphic driver with support of MongoDB, File (FS) and Console',
git: 'https://github.com/VeliovGroup/Meteor-logger',
documentation: 'README.md'
Expand Down

0 comments on commit 4b1ce00

Please sign in to comment.