Ember.Logger is a robust type of logging in Ember. It goes beyond the capabilities of imports.console
. In this recipe, we'll take a look at some examples on how to work with it in your application.
In this project, we'll create a simple program that demonstrates how to use some of the Ember.logging
capabilities:
index
route:$ ember g route index
This will create a new index
route.
index.js
file in the routes
folder. Add some new logging:// app/routes/index.js import Ember from 'ember'; const {Logger}= Ember; export default Ember.Route.extend({ model(){ Logger.log('log'); Logger.info('info', 'more stuff'); Logger.error('error'); Logger.debug('debug'); Logger.warn('warn'); Logger.assert(true === false); return {}; } });
Ember.logging
gives us five different logging options. All these different types of log
methods accept one or more arguments. Each argument will be joined together and separated by a space when written to the browser console window:
Logger.log('log');
Logger.info('info', 'more stuff');
The info
logger logs a message to the console as an info
message. In Firefox and Chrome, a small I icon is displayed next to the item:
Logger.error('error');
The error
log prints to the console with an error icon, red text, and stack trace.
Logger.debug('debug');
The debug
log prints to the console in blue text.
Logger.warn('warn');
The warning log will print to the console with a warning icon.
Logger.assert(true === false);
The assert
statement will return an error and stack trace if the value returns false
.