From fb0a1c14aedb900b405a9b2706116b087579cdc9 Mon Sep 17 00:00:00 2001 From: Stefan Profanter Date: Mon, 22 Jun 2015 15:39:47 +0200 Subject: [PATCH 1/2] Added definition for loglevel (https://github.com/pimterry/loglevel) --- loglevel/loglevel-tests.ts | 20 ++++++++ loglevel/loglevel.d.ts | 98 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 loglevel/loglevel-tests.ts create mode 100644 loglevel/loglevel.d.ts diff --git a/loglevel/loglevel-tests.ts b/loglevel/loglevel-tests.ts new file mode 100644 index 0000000000..8284134f33 --- /dev/null +++ b/loglevel/loglevel-tests.ts @@ -0,0 +1,20 @@ +/// + +log.trace("Trace message"); +log.debug("Debug message"); +log.info("Info message"); +log.warn("Warn message"); +log.error("Error message"); + +log.setLevel(0); +log.setLevel(0, false); + +log.setLevel("error"); +log.setLevel("error", false); + +log.setLevel(log.levels.WARN); +log.setLevel(log.levels.WARN, false); + +var logging = log.noConflict(); + +logging.error("still pretty easy"); diff --git a/loglevel/loglevel.d.ts b/loglevel/loglevel.d.ts new file mode 100644 index 0000000000..6644d026cb --- /dev/null +++ b/loglevel/loglevel.d.ts @@ -0,0 +1,98 @@ +// Type definitions for loglevel 1.3.1 +// Project: https://github.com/pimterry/loglevel +// Definitions by: Stefan Profanter +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module loglevel { + + /** + * Log levels + */ + export enum levels { + TRACE = 0, + DEBUG = 1, + INFO = 2, + WARN = 3, + ERROR = 4, + SILENT = 5 + } + + /** + * Output trace message to console. + * This will also include a full stack trace + * + * @param msg the message to print + */ + export function trace(msg:string):void; + + /** + * Output debug message to console including appropriate icons + * @param msg the message to print + */ + export function debug(msg:string):void; + + /** + * Output info message to console including appropriate icons + * @param msg the message to print + */ + export function info(msg:string):void; + + /** + * Output warn message to console including appropriate icons + * @param msg the message to print + */ + export function warn(msg:string):void; + + /** + * Output error message to console including appropriate icons + * @param msg the message to print + */ + export function error(msg:string):void; + + + /** + * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") + * or log.error("something") will output messages, but log.info("something") will not. + * + * @param level 0=trace to 5=silent + * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling back + * to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass + * false as the optional 'persist' second argument, persistence will be skipped. + */ + export function setLevel(level:number, persist?:boolean):void; + + + /** + * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") + * or log.error("something") will output messages, but log.info("something") will not. + * + * @param level as a string, like 'error' (case-insensitive) + * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling back + * to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass + * false as the optional 'persist' second argument, persistence will be skipped. + */ + export function setLevel(level:string, persist?:boolean):void; + + + /** + * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") + * or log.error("something") will output messages, but log.info("something") will not. + * + * @param level as the value from the enum + * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling back + * to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass + * false as the optional 'persist' second argument, persistence will be skipped. + */ + export function setLevel(level:levels, persist?:boolean):void; + + /** + * If you're using another JavaScript library that exposes a 'log' global, you can run into conflicts with loglevel. + * Similarly to jQuery, you can solve this by putting loglevel into no-conflict mode immediately after it is loaded + * onto the page. This resets to 'log' global to its value before loglevel was loaded (typically undefined), and + * returns the loglevel object, which you can then bind to another name yourself. + */ + export function noConflict():any; +} + +declare +var log:typeof loglevel; From 625232f072d61739c765a8d9c794c301e86858dd Mon Sep 17 00:00:00 2001 From: Stefan Profanter Date: Mon, 22 Jun 2015 16:01:44 +0200 Subject: [PATCH 2/2] Changed message type to any --- loglevel/loglevel-tests.ts | 1 + loglevel/loglevel.d.ts | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/loglevel/loglevel-tests.ts b/loglevel/loglevel-tests.ts index 8284134f33..2c4f89733d 100644 --- a/loglevel/loglevel-tests.ts +++ b/loglevel/loglevel-tests.ts @@ -5,6 +5,7 @@ log.debug("Debug message"); log.info("Info message"); log.warn("Warn message"); log.error("Error message"); +log.debug(["Hello", "world", 42]); log.setLevel(0); log.setLevel(0, false); diff --git a/loglevel/loglevel.d.ts b/loglevel/loglevel.d.ts index 6644d026cb..01b80b7222 100644 --- a/loglevel/loglevel.d.ts +++ b/loglevel/loglevel.d.ts @@ -21,33 +21,37 @@ declare module loglevel { * Output trace message to console. * This will also include a full stack trace * - * @param msg the message to print + * @param msg any data to log to the console */ - export function trace(msg:string):void; + export function trace(msg:any):void; /** * Output debug message to console including appropriate icons - * @param msg the message to print + * + * @param msg any data to log to the console */ - export function debug(msg:string):void; + export function debug(msg:any):void; /** * Output info message to console including appropriate icons - * @param msg the message to print + * + * @param msg any data to log to the console */ - export function info(msg:string):void; + export function info(msg:any):void; /** * Output warn message to console including appropriate icons - * @param msg the message to print + * + * @param msg any data to log to the console */ - export function warn(msg:string):void; + export function warn(msg:any):void; /** * Output error message to console including appropriate icons - * @param msg the message to print + * + * @param msg any data to log to the console */ - export function error(msg:string):void; + export function error(msg:any):void; /**