albertovasquez / ember-debug-logger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ember-debug-logger Build Status

ember-debug-logger exposes the visionmedia/debug library for use in your Ember.js application.

Installation

ember install ember-debug-logger

Usage

Enabling Namespaces During Debugging

During development, you can enable logging for particular namespaces calling debug.enable in the developer console. Your preferences will be persisted in local storage, but they're only checked when a logger is instantiated, so in most cases you'll need to refresh the page to see them take effect.

Enabled namespaces follow simple globbing rules, so to enable logging for everything, you could use:

debug.enable('*');

To enable only logging coming from the application route:

debug.enable('route:application');

You can mix and match as well. To enable logging for all routes and the foo-bar service, for instance:

debug.enable('route:*, service:foo-bar');

You can turn off all logging with disable:

debug.disable();

Namespaces will automatically be differentiated by color, and the time between messages will be logged.

image

Automatic Namespacing

By default, this addon will inject a debug method on to all routes, components, controllers, and services that are instantiated by your application's container. This method will automatically use its instance's container key as the namespace.

// index/route.js
import Ember from 'ember';

export default Ember.Route.extend({
  activate() {
    this.debug('Hello from the application index.');
  }
});

image

You can also manually add the method when defining any other class that will be instantiated by the container.

import Ember from 'ember';
import DS from 'ember-data';
import debugLogger from 'ember-debug-logger';

export default DS.RESTAdapter.extend({
  debug: debugLogger(),
  
  _sayHi: Ember.on('init', function() {
    this.debug('Hello from the application adapter!');
  })
});

image

Manual Namespacing

If you want to log debug messages from anywhere other than a container-managed object, you can manually specify a namespace in the same way you would with the underlying debug library.

import debugLogger from 'ember-debug-logger';
const debug = debugLogger('demo-namespace');

debug('Hello, world');

image

About

License:MIT License


Languages

Language:JavaScript 85.0%Language:HTML 15.0%