diff --git a/loglevel/loglevel-tests.ts b/loglevel/loglevel-tests.ts new file mode 100644 index 0000000000..2c4f89733d --- /dev/null +++ b/loglevel/loglevel-tests.ts @@ -0,0 +1,21 @@ +/// + +log.trace("Trace message"); +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); + +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..01b80b7222 --- /dev/null +++ b/loglevel/loglevel.d.ts @@ -0,0 +1,102 @@ +// 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 any data to log to the console + */ + export function trace(msg:any):void; + + /** + * Output debug message to console including appropriate icons + * + * @param msg any data to log to the console + */ + export function debug(msg:any):void; + + /** + * Output info message to console including appropriate icons + * + * @param msg any data to log to the console + */ + export function info(msg:any):void; + + /** + * Output warn message to console including appropriate icons + * + * @param msg any data to log to the console + */ + export function warn(msg:any):void; + + /** + * Output error message to console including appropriate icons + * + * @param msg any data to log to the console + */ + export function error(msg:any):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;