That depends on two main factors:
- Lightweight logging, such as exception handling and tracing can be handled on Mongo as a separate collection.
- Tracebacks, status management, etc (Heavyweight logging), better use a local / cloud file system for this.
There is no pre-built logging solution for Meteor, but also remember Meteor is a NodeJS app and unless you’re working with <1.3 versions then you can make use of NPM packages that best suit your needs.
In my case, I use log4JS and avoid logging into database as that will decrease overall performace and availability.
In general, logging is an architecture design, which means it’s purpose specific.
My recommendation would be to build a Logger controller yourself that you can import into each specific method and is able to monitor Method arguments and state, something like this:
// on Method declaration
method(...args){
if(!this.userId){ throw new Meteor.Error('Not authorized') }
const loggerComposite = new Logger('method.name');
loggerComposite.assignUser(this.userId);
loggerComposite.argumentsUsed(...args);
// For sensitive methods, use a try / catch
try{
// Logic goes here
loggerComposite.success(returnedResult);
} catch(err) {
loggerComposite.error(err);
// Handle error on method as you please
} finally {
loggerComposite.terminate();
}
}
Try catch block is pretty useful, and will only show a performance impact when used on extremely demanding method calls (something like +500 ms per 20’000 calls, you can test it with a loop yourself).
The idea behind is to allow your Logger controller to format things as you need it, either save a JSON file such as:
[{
status: success / fail;
date: new Date(),
method: 'method.name',
userId: 'USERID',
arguments: [...args],
success: null || result,
error: error.message
}]
Otherwise you can also use a logger to handle all functionality behind the curtain and just replace the usage you have with console.log:
const logger = new LoggerController();
logger.log('debug', this.userId);
logger.log('info', this.userId);
logger.log('error', this.userId);
This last method will emulate a raw log output, compatible with any unstructured file type you want (txt, csv, etc.)
The former has a more report-like approach, which can be latter processed in UNIX / node, etc. as you want.
Just remember, don’t clog your mongo process or your reactivity will be impacted.
Footnote:
There used to be a service called Kadira which logged permormace on Meteor methods, it’s been opensourced and taken down for a number of reasons (see end of transmission). You can set your standalone performance monitor here: https://github.com/kadira-open/kadira-server