Skip to content

Commit

Permalink
Merge pull request #11 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v1.1.2
 - Now you can pass your own `Mongo.Collection` instance
 - Codebase enhancements and fixes
 - Dependencies update
 - Docs update
  • Loading branch information
dr-dimitru committed May 20, 2016
2 parents d457fdb + b12100c commit d532237
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .versions
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ [email protected]
[email protected]
[email protected]
[email protected]
ostrio:[email protected].1
ostrio:[email protected].1
ostrio:[email protected].2
ostrio:[email protected].2
[email protected]
[email protected]
[email protected]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, dr.dimitru (Veliov Group LLC.)
Copyright (c) 2016, dr.dimitru (Dmitriy A.; Veliov Group, LLC)
All rights reserved.

Redistribution and use in source and binary forms,
Expand Down
58 changes: 44 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,53 @@ Usage
`new LoggerMongo(LoggerInstance, options)`
- `LoggerInstance` {*Logger*} - from `new Logger()`
- `options` {*Object*}
- `options.collection` {*Mongo.Collection*} - Use to pass your own MongoDB collection instance, {*[Mongo.Collection](Mongo.Collection)*} returned from `new Mongo.Collection()`
- `options.collectionName` {*String*} - MongoDB collection name, default: `ostrioMongoLogger`
- __Note__: *You can't pass both* `collection` *and* `collectionName` *simultaneously. Set only one of those options.* If both options is presented `collection` is more prioritized
- __Note__: If `collectionName` or no arguments is passed, `update`, `remove`, `insert` is disallowed on the Client

Example:
```javascript
this.log = new Logger(); // Initialize Logger
// Initialize LoggerMongo:
// Initialize Logger:
this.log = new Logger();

// Initialize LoggerMongo and enable with default settings:
(new LoggerMongo(log)).enable();
```

Example 2:
```javascript
// Initialize Logger:
this.log = new Logger();
var AppLogs = new Mongo.Collection('AppLogs');

// Initialize LoggerMongo with own collection instance:
var LogMongo = new LoggerMongo(log, {
collectionName: 'AppLogs' /* Use custom collection name */
collection: AppLogs
});

// Enable LoggerMongo with default settings:
LogMongo.enable();
```

Example 3:
```javascript
// Initialize Logger:
this.log = new Logger();

// Initialize LoggerMongo with custom collection name:
var LogMongo = new LoggerMongo(log, {
collectionName: 'AppLogs'
});

LogMongo.enable(); // Enable LoggerMongo with default settings
// Enable LoggerMongo with default settings:
LogMongo.enable();
```

##### Activate and set adapter settings: [*Isomorphic*]
##### Activate with custom adapter settings: [*Isomorphic*]
```javascript
this.log = new Logger();
new LoggerMongo(log, {}).enable({
(new LoggerMongo(log, {})).enable({
enable: true,
filter: ['ERROR', 'FATAL', 'WARN'], /* Filters: 'ERROR', 'FATAL', 'WARN', 'DEBUG', 'INFO', 'TRACE', '*' */
client: false, /* This allows to call, but not execute on Client */
Expand Down Expand Up @@ -72,7 +102,7 @@ new LoggerMongo(log, {}).enable({
});
```

##### Set custom indexes on collection:
##### Set custom indexes on collection: [*Server*]
Read more at: [ensureIndex docs](https://docs.mongodb.org/manual/reference/method/db.collection.ensureIndex/)
```javascript
this.log = new Logger();
Expand All @@ -91,7 +121,7 @@ if (Meteor.isServer) {
##### Log message: [*Isomorphic*]
```javascript
this.log = new Logger();
new LoggerMongo(log).enable();
(new LoggerMongo(log)).enable();

/*
message {String} - Any text message
Expand All @@ -110,7 +140,7 @@ log._(message, data, userId); //--> Plain log without level
throw log.error(message, data, userId);
```

##### Catch-all Client's errors example: [*CLIENT*]
##### Catch-all Client's errors example: [*Client*]
```javascript
/* Store original window.onerror */
var _WoE = window.onerror;
Expand All @@ -123,7 +153,7 @@ window.onerror = function(msg, url, line) {
};
```

##### Use multiple logger(s) with different settings:
##### Use multiple logger(s) with different settings: [*Isomorphic*]
```javascript
this.log1 = new Logger();
this.log2 = new Logger();
Expand All @@ -132,9 +162,9 @@ this.log2 = new Logger();
* Separate settings and collection
* for info, debug and other messages
*/
new LoggerMongo(log1, {
(new LoggerMongo(log1, {
collectionName: 'AppLogs'
}).enable({
})).enable({
filter: ['DEBUG', 'INFO', 'LOG', 'TRACE'],
client: false,
server: true
Expand All @@ -144,9 +174,9 @@ new LoggerMongo(log1, {
* Separate settings and collection
* for errors, exceptions, warnings and etc.
*/
new LoggerMongo(log2, {
(new LoggerMongo(log2, {
collectionName: 'AppErrors'
}).enable({
})).enable({
filter: ['ERROR', 'FATAL', 'WARN'],
client: false,
server: true
Expand Down
33 changes: 24 additions & 9 deletions loggermongo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ NOOP = -> return
class LoggerMongo
constructor: (@logger, @options = {}) ->
check @logger, Match.OneOf Logger, Object
check @options, Object
check @options, {
collectionName: Match.Optional String
collection: Match.Optional Match.OneOf Mongo.Collection, Object
}

if not @options.collectionName and not @options.collection
throw new Meteor.Error 400, '[LoggerMongo]: `collectionName` or `collection` must be presented'

self = @
if Meteor.isServer
@options.collectionName ?= "ostrioMongoLogger"
check @options.collectionName, String
@collection = new Meteor.Collection @options.collectionName
@collection.deny
update: -> true
remove: -> true
insert: -> true
if @options.collection
@collection = @options.collection
else
@options.collectionName ?= "ostrioMongoLogger"
@collection = new Meteor.Collection @options.collectionName
@collection.deny
update: -> true
remove: -> true
insert: -> true

self.logger.add 'Mongo', (level, message, data = null, userId) ->
if Meteor.isServer
Expand All @@ -39,9 +47,16 @@ class LoggerMongo
, true

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

rule.enable ?= true
rule.client ?= false
rule.server ?= true

@logger.rule 'Mongo', rule
return @
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:loggermongo',
version: '1.1.1',
version: '1.1.2',
summary: 'Logging: Store application log messages into MongoDB (Server & Client support)',
git: 'https://github.com/VeliovGroup/Meteor-logger-mongo',
documentation: 'README.md'
Expand All @@ -9,7 +9,7 @@ Package.describe({
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use('mongo', 'server');
api.use(['ostrio:[email protected].1', 'coffeescript', 'check', 'underscore'], ['client', 'server']);
api.use(['ostrio:[email protected].2', 'coffeescript', 'check', 'underscore'], ['client', 'server']);
api.addFiles('loggermongo.coffee', ['client', 'server']);
api.export('LoggerMongo');
});

0 comments on commit d532237

Please sign in to comment.