Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
 - New API, please read new updated README.md
 - Compatibility with Meteor >= 1.3.*
 - Performance and Security enhancements
 - All code is asynchronous!
 - Use own namespace
  • Loading branch information
dr-dimitru committed Apr 18, 2016
1 parent b9d5fcc commit 37ab907
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 121 deletions.
52 changes: 42 additions & 10 deletions .npm/package/npm-shrinkwrap.json

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

22 changes: 1 addition & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
Changelog
=========
- [[`v1.0.1`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/1.0.1)] *03/23/2016*
- Dependencies update
- Better Windows support
- [[`v1.0.0`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v1.0.0)] *07/01/2015*
- Deps packages update see [ostrio:logger@1.0.0](https://github.com/VeliovGroup/Meteor-logger/releases/tag/v1.0.0)
- [[`v0.0.11`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.11)] *06/07/2015*
- Deps packages update
- [[`v0.0.10`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.10)] *05/29/2015*
- Deps packages update
- Add Changelog.md
- [[`v0.0.9`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.9)] *05/28/2015*
- Fix issue #2
- Remove colon from file names, to avoid Windows compilation issues
- License update
- [[`v0.0.8`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.8)] *05/25/2015*
- Deps packages update
- [[`v0.0.7`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.7)] *04/12/2015*
- Use `ostrio:meteor-root` to find Meteor's root folder
- [[`v0.0.6`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.6)] *04/10/2015*
- Fix storage path for PRODUCTION ENV
- [[`v0.0.5`](https://github.com/VeliovGroup/Meteor-logger-file/releases/tag/v0.0.5)] Initial, please see docs
For full package history, please see [releases at GitHub](https://github.com/VeliovGroup/Meteor-logger-file/releases)
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
History
=========
For full package history, please see [releases at GitHub](https://github.com/VeliovGroup/Meteor-logger-file/releases)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, Dmitriy A. (Veliov Group, LLC)
Copyright (c) 2016, dr.dimitru (Veliov Group LLC.)
All rights reserved.

Redistribution and use in source and binary forms,
Expand Down
116 changes: 76 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,102 @@
Meteor file adapter for ostrio:logger
Logging: To File
========
Simply store application logs into file within [ostrio:logger](https://atmospherejs.com/ostrio/logger) package

*Whenever you log message(s) on client or sever, it goes directly to log-file on your server.*

Installation:
========
```shell
meteor add ostrio:logger # If not yet installed
meteor add ostrio:loggerfile
```

Usage
========
##### Log [`Server` & `Client`]
##### Initialization [*Isomorphic*]
`new LoggerFile(LoggerInstance, options)`
- `LoggerInstance` {*Logger*} - from `new Logger()`
- `options` {*Object*}
- `options.fileNameFormat` {*Function*} - Log file name, use to adjust file creation frequency, arguments:
- `time` {*Date*}
- `options.format` {*Function*} - Log record format, arguments:
- `time` {*Date*}
- `level` {*String*} - 'ERROR', 'FATAL', 'WARN', 'DEBUG', 'INFO'
- `message` {*String*}
- `data` {*Object*}
- `userId` {*String*} - set if user is logged in and package `accounts-base` is installed
- Note: Do not forget `\r\n` at the end of record-line
- `path` {*String*} - Log's storage path, absolute, or relative to NodeJS process, note: do not use '~' (path relative to user)!

Example:
```javascript
/*
message {String} - Any text message
data {Object} - [optional] Any additional info as object
userId {String} - [optional] Current user id
*/
Meteor.log.info(message, data, userId);
Meteor.log.debug(message, data, userId);
Meteor.log.error(message, data, userId);
Meteor.log.fatal(message, data, userId);
Meteor.log.warn(message, data, userId);
Meteor.log.trace(message, data, userId);
Meteor.log._(message, data, userId); //--> Shortcut for logging without message, e.g.: simple plain log
this.Log = new Logger();
var LogFile = new LoggerFile(Log, {
fileNameFormat: function(time) {
/* Create log-files hourly */
return (time.getDate()) + "-" + (time.getMonth() + 1) + "-" + (time.getFullYear()) + "_" + (time.getHours()) + ".log";
},
format: function(time, level, message, data, userId) {
/* Omit Date and hours from messages */
return "[" + level + "] | " + (time.getMinutes()) + ":" + (time.getSeconds()) + " | \"" + message + "\" | User: " + userId + "\r\n";
},
path: '/data/logs/' /* Use absolute storage path */
});
```

##### Activate and set adapter settings [`Server` & `Client`]
##### Activate and set adapter settings [*Isomorphic*]
```javascript
Meteor.log.rule('File',
{
this.Log = new Logger();
new LoggerFile(Log, {}).enable({
enable: true,
filter: ['ERROR', 'FATAL', 'WARN'], /* Filters: 'ERROR', 'FATAL', 'WARN', 'DEBUG', 'INFO', '*' */
filter: ['ERROR', 'FATAL', 'WARN'], /* Filters: 'ERROR', 'FATAL', 'WARN', 'DEBUG', 'INFO', 'TRACE', '*' */
client: false, /* This allows to call, but not execute on Client */
server: true /* Calls from client will be executed on Server */
});
```

##### Change string format [`Server`]
Default format:
```coffeescript
"#{time.getDate()}-#{time.getMonth()}-#{time.getFullYear()} #{time.getHours()}:#{time.getMinutes()}:#{time.getSeconds()} | [#{level}] | Message: \"#{message}\" | User: #{userId} | data: #{data}\r\n"
```
##### Log [*Isomorphic*]
```javascript
this.Log = new Logger();
new LoggerFile(Log).enable();

To change format set `Meteor.log.file.format` function
```coffeescript
if Meteor.isServer
Meteor.log.file.format = (time, level, message, data, userId) ->
"#{+time} [#{level}]: \"#{message}\" \r\n"
```
/*
message {String} - Any text message
data {Object} - [optional] Any additional info as object
userId {String} - [optional] Current user id
*/
Log.info(message, data, userId);
Log.debug(message, data, userId);
Log.error(message, data, userId);
Log.fatal(message, data, userId);
Log.warn(message, data, userId);
Log.trace(message, data, userId);
Log._(message, data, userId); //--> Shortcut for logging without message, e.g.: simple plain log

##### Change file name format [`Server`]
Default format:
```coffeescript
# New file will be created every day
"#{time.getDate()}-#{time.getMonth()}-#{time.getFullYear()}.log"
/* Use with throw */
throw Log.error(message, data, userId);
```

To change format set `Meteor.log.file.fileNameFormat` function
```coffeescript
if Meteor.isServer
Meteor.log.file.fileNameFormat = (time) ->
# New file will be created every hour
"#{time.getHours()}_#{time.getDate()}-#{time.getMonth()}-#{time.getFullYear()}.log"
##### Use multiple logger(s) with different settings:
```javascript
this.Log1 = new Logger();
this.Log2 = new Logger();

new LoggerFile(Log1).enable({
client: false,
server: true
});

new LoggerFile(Log2, {
fileNameFormat: function(time) {
return (time.getDate()) + "-" + (time.getMonth() + 1) + "-" + (time.getFullYear()) + "_" + (time.getHours()) + ".log";
},
format: function(time, level, message, data, userId) {
return "[" + level + "] | " + (time.getMinutes()) + ":" + (time.getSeconds()) + " | \"" + message + "\" | User: " + userId + "\r\n";
},
path: '/data/logs/'
}).enable({
client: false,
server: true
});
```
Loading

0 comments on commit 37ab907

Please sign in to comment.