Skip to content

Commit

Permalink
chore(all): prepare release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Feb 21, 2017
1 parent 754a14f commit 3b82212
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 421 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-logging",
"version": "1.2.0",
"version": "1.3.0",
"description": "A minimal but effective logging mechanism with support for log levels and pluggable log appenders.",
"keywords": [
"aurelia",
Expand Down
107 changes: 38 additions & 69 deletions dist/amd/aurelia-logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(['exports'], function (exports) {
});
exports.getLogger = getLogger;
exports.addAppender = addAppender;
exports.removeAppender = removeAppender;
exports.setLevel = setLevel;
exports.getLevel = getLevel;

Expand All @@ -21,87 +22,54 @@ define(['exports'], function (exports) {

var loggers = {};
var appenders = [];
var slice = Array.prototype.slice;
var loggerConstructionKey = {};
var globalDefaultLevel = logLevel.none;

function log(logger, level, args) {
var i = appenders.length;
var current = void 0;

args = slice.call(args);
args.unshift(logger);

while (i--) {
current = appenders[i];
current[level].apply(current, args);
}
}

function debug() {
if (this.level < 4) {
return;
}

log(this, 'debug', arguments);
}

function info() {
if (this.level < 3) {
return;
}

log(this, 'info', arguments);
}

function warn() {
if (this.level < 2) {
return;
}

log(this, 'warn', arguments);
function appendArgs() {
return [this].concat(Array.prototype.slice.call(arguments));
}

function error() {
if (this.level < 1) {
return;
}
function logFactory(level) {
var threshold = logLevel[level];
return function () {
if (this.level < threshold) {
return;
}

log(this, 'error', arguments);
}
var args = appendArgs.apply(this, arguments);
var i = appenders.length;
while (i--) {
var _appenders$i;

function connectLogger(logger) {
logger.debug = debug;
logger.info = info;
logger.warn = warn;
logger.error = error;
(_appenders$i = appenders[i])[level].apply(_appenders$i, args);
}
};
}

function createLogger(id) {
var logger = new Logger(id, loggerConstructionKey);
logger.setLevel(globalDefaultLevel);

if (appenders.length) {
connectLogger(logger);
}

return logger;
function connectLoggers() {
Object.assign(Logger.prototype, {
debug: logFactory('debug'),
info: logFactory('info'),
warn: logFactory('warn'),
error: logFactory('error')
});
}

function getLogger(id) {
return loggers[id] || (loggers[id] = createLogger(id));
return loggers[id] || new Logger(id);
}

function addAppender(appender) {
appenders.push(appender);

if (appenders.length === 1) {
for (var key in loggers) {
connectLogger(loggers[key]);
}
if (appenders.push(appender) === 1) {
connectLoggers();
}
}

function removeAppender(appender) {
appenders = appenders.filter(function (a) {
return a !== appender;
});
}

function setLevel(level) {
globalDefaultLevel = level;
for (var key in loggers) {
Expand All @@ -114,16 +82,17 @@ define(['exports'], function (exports) {
}

var Logger = exports.Logger = function () {
function Logger(id, key) {
function Logger(id) {


this.level = logLevel.none;

if (key !== loggerConstructionKey) {
throw new Error('Cannot instantiate "Logger". Use "getLogger" instead.');
var cached = loggers[id];
if (cached) {
return cached;
}

loggers[id] = this;
this.id = id;
this.level = globalDefaultLevel;
}

Logger.prototype.debug = function debug(message) {};
Expand Down
8 changes: 7 additions & 1 deletion dist/aurelia-logging.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export declare function getLogger(id: string): Logger;
*/
export declare function addAppender(appender: Appender): void;

/**
* Removes an appender
* @param appender An appender that has been added previously.
*/
export declare function removeAppender(appender: Appender): void;

/**
* Sets the level of logging for ALL the application loggers.
*
Expand Down Expand Up @@ -128,7 +134,7 @@ export declare class Logger {
/**
* You cannot instantiate the logger directly - you must use the getLogger method instead.
*/
constructor(id: string, key: Object);
constructor(id: string);

/**
* Logs a debug message.
Expand Down
113 changes: 43 additions & 70 deletions dist/aurelia-logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,71 +38,37 @@ export const logLevel: LogLevel = {

let loggers = {};
let appenders = [];
let slice = Array.prototype.slice;
let loggerConstructionKey = {};
let globalDefaultLevel = logLevel.none;

function log(logger, level, args) {
let i = appenders.length;
let current;

args = slice.call(args);
args.unshift(logger);

while (i--) {
current = appenders[i];
current[level].apply(current, args);
}
}

function debug() {
if (this.level < 4) {
return;
}

log(this, 'debug', arguments);
}

function info() {
if (this.level < 3) {
return;
}

log(this, 'info', arguments);
}

function warn() {
if (this.level < 2) {
return;
}

log(this, 'warn', arguments);
function appendArgs() {
return [this, ...arguments];
}

function error() {
if (this.level < 1) {
return;
}

log(this, 'error', arguments);
function logFactory(level) {
const threshold = logLevel[level];
return function() {
// In this function, this === logger
if (this.level < threshold) {
return;
}
// We don't want to disable optimizations (such as inlining) in this function
// so we do the arguments manipulation in another function.
// Note that Function#apply is very special for V8.
const args = appendArgs.apply(this, arguments);
let i = appenders.length;
while (i--) {
appenders[i][level](...args);
}
};
}

function connectLogger(logger) {
logger.debug = debug;
logger.info = info;
logger.warn = warn;
logger.error = error;
}

function createLogger(id) {
let logger = new Logger(id, loggerConstructionKey);
logger.setLevel(globalDefaultLevel);

if (appenders.length) {
connectLogger(logger);
}

return logger;
function connectLoggers() {
Object.assign(Logger.prototype, {
debug: logFactory('debug'),
info: logFactory('info'),
warn: logFactory('warn'),
error: logFactory('error')
});
}

/**
Expand All @@ -112,7 +78,7 @@ function createLogger(id) {
* @return The instance of the logger, or creates a new logger if none exists for that id.
*/
export function getLogger(id: string): Logger {
return loggers[id] || (loggers[id] = createLogger(id));
return loggers[id] || new Logger(id);
}

/**
Expand Down Expand Up @@ -158,15 +124,19 @@ interface Appender {
* @param appender An appender instance to begin processing logs with.
*/
export function addAppender(appender: Appender): void {
appenders.push(appender);

if (appenders.length === 1) {
for (let key in loggers) {
connectLogger(loggers[key]);
}
if (appenders.push(appender) === 1) {
connectLoggers();
}
}

/**
* Removes an appender
* @param appender An appender that has been added previously.
*/
export function removeAppender(appender: Appender): void {
appenders = appenders.filter(a => a !== appender);
}

/**
* Sets the level of logging for ALL the application loggers.
*
Expand Down Expand Up @@ -200,17 +170,20 @@ export class Logger {
/**
* The logging severity level for this logger
*/
level: number = logLevel.none;
level: number;

/**
* You cannot instantiate the logger directly - you must use the getLogger method instead.
*/
constructor(id: string, key: Object) {
if (key !== loggerConstructionKey) {
throw new Error('Cannot instantiate "Logger". Use "getLogger" instead.');
constructor(id: string) {
let cached = loggers[id];
if (cached) {
return cached;
}

loggers[id] = this;
this.id = id;
this.level = globalDefaultLevel;
}

/**
Expand Down
Loading

0 comments on commit 3b82212

Please sign in to comment.