Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
 - Compatibility with `[email protected]`
 - Dependencies update
 - Exact code splitting between Server and Client, fix #9 , thanks to
@mddarko
  • Loading branch information
dr-dimitru committed Aug 1, 2017
1 parent eee0592 commit 9da7d60
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 75 deletions.
14 changes: 7 additions & 7 deletions .npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 25 additions & 23 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
[email protected].5
babel-compiler@6.18.2
[email protected].6
babel-compiler@6.19.4
[email protected]
[email protected]
[email protected]
blaze@2.1.9
blaze@2.3.2
[email protected]
boilerplate-generator@1.0.11
boilerplate-generator@1.1.1
[email protected]
[email protected]
ddp@1.2.5
ddp-client@1.3.4
[email protected].8
ddp-server@1.3.14
ddp@1.3.0
ddp-client@2.0.0
[email protected].9
ddp-server@2.0.0
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
local-test:ostrio:[email protected].0
local-test:ostrio:[email protected].1
[email protected]
meteor@1.6.1
minimongo@1.0.23
modules@0.8.2
modules-runtime@0.7.10
[email protected].17
meteor@1.7.0
minimongo@1.2.1
modules@0.9.2
modules-runtime@0.8.0
[email protected].19
[email protected]
[email protected]
[email protected]
[email protected]
ostrio:[email protected].2
ostrio:[email protected].0
ostrio:[email protected].3
ostrio:[email protected].1
ostrio:[email protected]
[email protected].8
[email protected].9
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].13
spacebars-compiler@1.0.13
[email protected].15
spacebars-compiler@1.1.2
[email protected]
[email protected]
[email protected].12
[email protected].13
[email protected]
[email protected].15
[email protected].17
[email protected]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,9 @@ const log2 = new Logger();
path: '/data/logs/'
})).enable();
```

Support this project:
========
This project can't be possible without [ostr.io](https://ostr.io).

By using [ostr.io](https://ostr.io) you are not only [protecting domain names](https://ostr.io/info/domain-names-protection), [monitoring websites and servers](https://ostr.io/info/monitoring), using [Prerendering for better SEO](https://ostr.io/info/prerendering) of your JavaScript website, but support our Open Source activity, and great packages like this one are available for free.
42 changes: 42 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Logger } from 'meteor/ostrio:logger';
import { check, Match } from 'meteor/check';
const NOOP = () => {};

/*
* @class LoggerFile
* @summary File (FS) adapter for ostrio:logger (Logger)
*/
class LoggerFile {
constructor(logger, options = {}) {
check(logger, Match.OneOf(Logger, Object));
check(options, Match.Optional(Object));

this.logger = logger;
this.options = options;
this.logger.add('File', NOOP, NOOP, false, false);
}

enable(rule = {}) {
check(rule, {
enable: Match.Optional(Boolean),
client: Match.Optional(Boolean),
server: Match.Optional(Boolean),
filter: Match.Optional([String])
});

if (rule.enable == null) {
rule.enable = true;
}
if (rule.client == null) {
rule.client = true;
}
if (rule.server == null) {
rule.server = true;
}

this.logger.rule('File', rule);
return this;
}
}

export { LoggerFile };
12 changes: 7 additions & 5 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:loggerfile',
version: '2.0.0',
version: '2.0.1',
summary: 'Logging: Store application\'s logs into file (Server & Client support)',
git: 'https://github.com/VeliovGroup/Meteor-logger-file',
documentation: 'README.md'
Expand All @@ -9,16 +9,18 @@ Package.describe({
Package.onUse(function(api) {
api.versionsFrom('1.4');
api.use('ostrio:[email protected]', 'server');
api.use(['ecmascript', 'check', 'underscore', 'ostrio:[email protected]'], ['client', 'server']);
api.mainModule('loggerfile.js', ['client', 'server']);
api.use(['ecmascript', 'check', 'ostrio:[email protected]'], ['client', 'server']);
api.use('underscore', 'server');
api.mainModule('client.js', 'client');
api.mainModule('server.js', 'server');
});

Package.onTest(function(api) {
api.use('tinytest');
api.use(['ecmascript', 'underscore', 'ostrio:[email protected].2', 'ostrio:[email protected].0']);
api.use(['ecmascript', 'underscore', 'ostrio:[email protected].3', 'ostrio:[email protected].1']);
api.addFiles('loggerfile-tests.js');
});

Npm.depends({
'fs-extra': '3.0.1'
'fs-extra': '4.0.1'
});
71 changes: 31 additions & 40 deletions loggerfile.js → server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import { _ } from 'meteor/underscore';
import { Meteor } from 'meteor/meteor';
import { Logger } from 'meteor/ostrio:logger';
import { check, Match } from 'meteor/check';

let fs = {};
import fs from 'fs-extra';
const NOOP = () => {};

if (Meteor.isServer) {
fs = require('fs-extra');
}

/*
* @class LoggerFile
* @summary File (FS) adapter for ostrio:logger (Logger)
Expand All @@ -22,32 +17,30 @@ class LoggerFile {
this.logger = logger;
this.options = options;

if (Meteor.isServer) {
/* fileNameFormat - Log file name */
if (this.options.fileNameFormat) {
if (!_.isFunction(this.options.fileNameFormat)) {
throw new Meteor.Error('[LoggerFile] [options.fileNameFormat] Must be a Function!');
/* fileNameFormat - Log file name */
if (this.options.fileNameFormat) {
if (!_.isFunction(this.options.fileNameFormat)) {
throw new Meteor.Error('[LoggerFile] [options.fileNameFormat] Must be a Function!');
}
} else {
this.options.fileNameFormat = (time) => {
let month = `${time.getMonth() + 1}`;
if (month.length === 1) {
month = '0' + month;
}
} else {
this.options.fileNameFormat = (time) => {
let month = `${time.getMonth() + 1}`;
if (month.length === 1) {
month = '0' + month;
}

let date = `${time.getDate()}`;
if (date.length === 1) {
date = '0' + date;
}
let date = `${time.getDate()}`;
if (date.length === 1) {
date = '0' + date;
}

let year = `${time.getFullYear()}`;
if (year.length === 1) {
year = '0' + year;
}
let year = `${time.getFullYear()}`;
if (year.length === 1) {
year = '0' + year;
}

return `${date}-${month}-${year}.log`;
};
}
return `${date}-${month}-${year}.log`;
};

/* format - Log record format */
if (this.options.format) {
Expand Down Expand Up @@ -111,20 +104,18 @@ class LoggerFile {
}

this.logger.add('File', (level, message, data = null, userId) => {
if (Meteor.isServer) {
const time = new Date();
let _data = null;

if (data) {
_data = this.logger.antiCircular(_.clone(data));
if (_.isString(_data.stackTrace)) {
_data.stackTrace = _data.stackTrace.split(/\n|\\n|\r|\r\n/g);
}
_data = JSON.stringify(_data, false, 2);
}
const time = new Date();
let _data = null;

fs.appendFile(`${this.options.path}/${this.options.fileNameFormat(time)}`, this.options.format(time, level, message, _data, userId), NOOP);
if (data) {
_data = this.logger.antiCircular(_.clone(data));
if (_.isString(_data.stackTrace)) {
_data.stackTrace = _data.stackTrace.split(/\n|\\n|\r|\r\n/g);
}
_data = JSON.stringify(_data, false, 2);
}

fs.appendFile(`${this.options.path}/${this.options.fileNameFormat(time)}`, this.options.format(time, level, message, _data, userId), NOOP);
}, NOOP, false, false);
}

Expand Down

0 comments on commit 9da7d60

Please sign in to comment.