'use strict';
//import _exports = require('_exports');
import _Global = require('./_Global');
import _Base = require('./_Base');
"use strict";
var _exports = _Global;
var spaceR = /\s+/g;
var typeR = /^(error|warn|info|log)$/;
var WinJSLog = null;
function format(message, tag, type) {
///
///
/// Adds tags and type to a logging message.
///
/// The message to format.
///
/// The tag(s) to apply to the message. Separate multiple tags with spaces.
///
/// The type of the message.
/// The formatted message.
///
var m = message;
if (typeof (m) === "function") { m = m(); }
return ((type && typeR.test(type)) ? ("") : (type ? (type + ": ") : "")) +
(tag ? tag.replace(spaceR, ":") + ": " : "") +
m;
}
function defAction(message, tag, type) {
var m = _exports.formatLog(message, tag, type);
if (_Global.console) {
_Global.console[(type && typeR.test(type)) ? type : "log"](m);
}
}
function escape(s) {
// \s (whitespace) is used as separator, so don't escape it
return s.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
}
_Base.Namespace._moduleDefine(undefined|| _Global, "WinJS.Utilities", {
startLog: function (options) {
///
///
/// Configures a logger that writes messages containing the specified tags from WinJS.log to console.log.
///
///
/// The tags for messages to log. Separate multiple tags with spaces.
///
///
///
///
/// Configure a logger to write WinJS.log output.
///
///
/// May contain .type, .tags, .excludeTags and .action properties.
/// - .type is a required tag.
/// - .excludeTags is a space-separated list of tags, any of which will result in a message not being logged.
/// - .tags is a space-separated list of tags, any of which will result in a message being logged.
/// - .action is a function that, if present, will be called with the log message, tags and type. The default is to log to the console.
///
///
options = options || {};
if (typeof options === "string") {
options = { tags: options };
}
var el = options.type && new RegExp("^(" + escape(options.type).replace(spaceR, " ").split(" ").join("|") + ")$");
var not = options.excludeTags && new RegExp("(^|\\s)(" + escape(options.excludeTags).replace(spaceR, " ").split(" ").join("|") + ")(\\s|$)", "i");
var has = options.tags && new RegExp("(^|\\s)(" + escape(options.tags).replace(spaceR, " ").split(" ").join("|") + ")(\\s|$)", "i");
var action = options.action || defAction;
if (!el && !not && !has && !_exports.log) {
_exports.log = action;
return;
}
var result:any = function (message, tag, type) {
if (!((el && !el.test(type)) // if the expected log level is not satisfied
|| (not && not.test(tag)) // if any of the excluded categories exist
|| (has && !has.test(tag)))) { // if at least one of the included categories doesn't exist
action(message, tag, type);
}
result.next && result.next(message, tag, type);
};
result.next = _exports.log;
_exports.log = result;
},
stopLog: function () {
///
///
/// Removes the previously set up logger.
///
///
_exports.log = null;
},
formatLog: format
});
var _winjsLog = {
log: {
get: function () {
return WinJSLog;
},
set: function (value) {
WinJSLog = value;
}
}
};
_Base.Namespace._moduleDefine(_exports, "WinJS", _winjsLog);
export var log = _exports.log;