Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

spike: basic injectable logger using console apis #25

Closed
wants to merge 1 commit into from

3 participants

@iammerrick

No description provided.

@iammerrick

Attention @IgorMinar

@iammerrick iammerrick added cla: yes and removed cla: no labels
@IgorMinar
Owner

I kind of like this better (to my surprise) if only we can agree on api for "around" instrumentation

@vojtajina

This is exactly what I wanted ;-)

@iammerrick

So much winking I can't tell if you are the worlds most sophisticated troll or just a nice guy. ;-)

@iammerrick iammerrick closed this
@iammerrick iammerrick deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +6 −1 src/injector.js
  2. +13 −0 src/logger.js
View
7 src/injector.js
@@ -4,6 +4,7 @@ import {getUniqueId} from './profiler';
// NOTE(vojta): should we rather use custom lightweight promise-like wrapper?
import {resolve} from 'q';
+import Logger from './logger';
var EmptyFunction = Object.getPrototypeOf(Function);
@@ -38,11 +39,14 @@ class Provider {
class Injector {
- constructor(modules = [], parentInjector = null, providers = new Map()) {
+ constructor(modules = [], parentInjector = null, providers = new Map(), logger = new Logger()) {
this.cache = new Map();
this.providers = providers;
this.parent = parentInjector;
this.id = getUniqueId();
+ this.logger = logger;
+
+ this.logger.info(`injector ${this.id} created`);
this._loadModules(modules);
}
@@ -260,6 +264,7 @@ class Injector {
instance = context;
}
+ this.logger.info(`${token} created`);
this.cache.set(token, instance);
if (!wantPromise && provider.isPromise) {
View
13 src/logger.js
@@ -0,0 +1,13 @@
+class Logger {
+ constructor(target) {
+ this.target = target || window.console;
+ }
+}
+
+['info', 'log', 'warn', 'error'].forEach(function(method) {
+ Logger.prototype[method] = function(message) {
+ this.target[method](message);
+ };
+});
+
+export default Logger;
Something went wrong with that request. Please try again.