diff --git a/.npm/package/npm-shrinkwrap.json b/.npm/package/npm-shrinkwrap.json index aeee493..7ca08dd 100644 --- a/.npm/package/npm-shrinkwrap.json +++ b/.npm/package/npm-shrinkwrap.json @@ -1,9 +1,9 @@ { "dependencies": { "fs-extra": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-3.0.1.tgz", - "from": "fs-extra@3.0.1" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.1.tgz", + "from": "fs-extra@4.0.1" }, "graceful-fs": { "version": "4.1.11", @@ -11,13 +11,13 @@ "from": "graceful-fs@>=4.1.2 <5.0.0" }, "jsonfile": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.0.tgz", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.1.tgz", "from": "jsonfile@>=3.0.0 <4.0.0" }, "universalify": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.0.tgz", + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", "from": "universalify@>=0.1.0 <0.2.0" } } diff --git a/.versions b/.versions index 3fa2aa4..683aa1c 100644 --- a/.versions +++ b/.versions @@ -1,51 +1,53 @@ -allow-deny@1.0.5 -babel-compiler@6.18.2 +allow-deny@1.0.6 +babel-compiler@6.19.4 babel-runtime@1.0.1 base64@1.0.10 binary-heap@1.0.10 -blaze@2.1.9 +blaze@2.3.2 blaze-tools@1.0.10 -boilerplate-generator@1.0.11 +boilerplate-generator@1.1.1 callback-hook@1.0.10 check@1.2.5 -ddp@1.2.5 -ddp-client@1.3.4 -ddp-common@1.2.8 -ddp-server@1.3.14 +ddp@1.3.0 +ddp-client@2.0.0 +ddp-common@1.2.9 +ddp-server@2.0.0 deps@1.0.12 diff-sequence@1.0.7 -ecmascript@0.7.3 -ecmascript-runtime@0.3.15 +ecmascript@0.8.1 +ecmascript-runtime@0.4.1 +ecmascript-runtime-client@0.4.3 +ecmascript-runtime-server@0.4.1 ejson@1.0.13 geojson-utils@1.0.10 html-tools@1.0.11 htmljs@1.0.11 id-map@1.0.9 jquery@1.11.10 -local-test:ostrio:loggerfile@2.0.0 +local-test:ostrio:loggerfile@2.0.1 logging@1.1.17 -meteor@1.6.1 -minimongo@1.0.23 -modules@0.8.2 -modules-runtime@0.7.10 -mongo@1.1.17 +meteor@1.7.0 +minimongo@1.2.1 +modules@0.9.2 +modules-runtime@0.8.0 +mongo@1.1.19 mongo-id@1.0.6 npm-mongo@2.2.24 observe-sequence@1.0.16 ordered-dict@1.0.9 -ostrio:logger@2.0.2 -ostrio:loggerfile@2.0.0 +ostrio:logger@2.0.3 +ostrio:loggerfile@2.0.1 ostrio:meteor-root@1.0.6 -promise@0.8.8 +promise@0.8.9 random@1.0.10 reactive-var@1.0.11 retry@1.0.9 routepolicy@1.0.12 -spacebars@1.0.13 -spacebars-compiler@1.0.13 +spacebars@1.0.15 +spacebars-compiler@1.1.2 tinytest@1.0.12 tracker@1.1.3 -ui@1.0.12 +ui@1.0.13 underscore@1.0.10 -webapp@1.3.15 +webapp@1.3.17 webapp-hashing@1.0.9 diff --git a/README.md b/README.md index f786607..5c6bbad 100755 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/client.js b/client.js new file mode 100644 index 0000000..1f9c9b2 --- /dev/null +++ b/client.js @@ -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 }; diff --git a/package.js b/package.js index 37815d5..b1af1dd 100755 --- a/package.js +++ b/package.js @@ -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' @@ -9,16 +9,18 @@ Package.describe({ Package.onUse(function(api) { api.versionsFrom('1.4'); api.use('ostrio:meteor-root@1.0.6', 'server'); - api.use(['ecmascript', 'check', 'underscore', 'ostrio:logger@2.0.2'], ['client', 'server']); - api.mainModule('loggerfile.js', ['client', 'server']); + api.use(['ecmascript', 'check', 'ostrio:logger@2.0.3'], ['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:logger@2.0.2', 'ostrio:loggerfile@2.0.0']); + api.use(['ecmascript', 'underscore', 'ostrio:logger@2.0.3', 'ostrio:loggerfile@2.0.1']); api.addFiles('loggerfile-tests.js'); }); Npm.depends({ - 'fs-extra': '3.0.1' + 'fs-extra': '4.0.1' }); diff --git a/loggerfile.js b/server.js similarity index 70% rename from loggerfile.js rename to server.js index b9afd5c..07d593a 100755 --- a/loggerfile.js +++ b/server.js @@ -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) @@ -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) { @@ -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); }