Advanced Server Logging Tools
Once you have both your server-side logging running, and your client side development tools, you can start looking at Meteor specific extensions like the Meteor Chrome DevTools Extension. This lets you actually observe server logging in the client! Because the database is everywhere. As is logging.
Basic Server Side Logging
The first step to logging is simply to run Meteor from the shell, and you'll get the server logs in the command console.
The next step is to pipe the contents of std_out and std_err to a logfile, like so:
Client Side Logging Tools
Once you have your server side logging in place, it's time to hop over to the client side. If you haven't explored the console API, be prepared for a treat. There's actually all sorts of things that you can do with the built in Console API that's native to every Chrome and Safari installation. So much so, in fact, that you may find yourself not needing Winston or other logging frameworks.
The first thing you'll want to do is install client side logging and developer tools. Chrome and Safari both ship with them, but Firefox requires the Firebug extension.
Then, you'll want to check out the Console API documentation. The following two documents are invaluable resources for learning console logging.
Disable Logging in Production
Some teams find that they want to leave console log statements in their code, but not have them display in production. They will override the logging functions if a variable isn't set (possibly an environment variable). Additionally, this may qualify as a security feature in some situations.
Logging error on database flap
The following example is from 0.5 - 0.7 days, and illustrates how to log an error when the database hasn't populated the client side cursor yet.
Logging events and user interactions
Simple example of using the Chrome Logging API.
Logging info on the data context in a template helper
The following uses the Chrome Logging API. If the
.group() syntax is used in multiple templates, it will graphically organize the console logs from different templates into a hierarchical tree.
You can also see how to inspect the current data context, and how to stringify data.
Logging with log level variables
Logging can often clutter up the console, so it's common to define log levels to control what detail of data is getting logged. A common pattern is to specify a log level variables.
A special mention should be made for the community developed LogLevel package. It appears to strike a balance between being lightweight and simple to use, while working well with Meteor's bundle pipeline and preserving line numbers and filenames.
If you need something more powerful than the default logging options, you might want to look at a tool like Winston. Go to Atmosphere, and simply search for one of the many Winston packages available.
Be warned, however - Winston is a sophisticated product, and while it exposes a lot of functionality, it will also add a layer of complexity to your application.