Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Type definitions for minilog v2 | ||
// Project: https://github.com/mixu/minilog | ||
// Definitions by: Guido <http://guido.io> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
/// <reference path="minilog.d.ts"/> | ||
|
||
|
||
//Following are example snippets from mixu.net/minilog | ||
|
||
var log = Minilog('app'); | ||
Minilog.enable(); | ||
|
||
log | ||
.debug('debug message') | ||
.info('info message') | ||
.warn('warning') | ||
.error('this is an error message'); | ||
|
||
Minilog.pipe(Minilog.backends.console.formatWithStack) | ||
.pipe(Minilog.backends.console); | ||
|
||
|
||
Minilog | ||
// formatter | ||
.pipe(Minilog.backends.console.formatClean) | ||
// backend | ||
.pipe(Minilog.backends.console); | ||
|
||
|
||
Minilog.pipe(Minilog.suggest) // filter | ||
.pipe(Minilog.defaultFormatter) // formatter | ||
.pipe(Minilog.defaultBackend); // backend - e.g. the console | ||
|
||
Minilog.suggest.deny(/mymodule\/.*/, 'warn'); | ||
|
||
Minilog | ||
.suggest | ||
.clear() | ||
.deny('foo', 'warn'); | ||
Minilog.enable(); | ||
|
||
Minilog.suggest.defaultResult = false; | ||
Minilog | ||
.suggest | ||
.clear() | ||
.allow('bar', 'info'); | ||
Minilog.enable(); | ||
|
||
|
||
var myFilter = new Minilog.Filter(); | ||
// allow any logs from the namespace/module "foo", level >= 'info | ||
myFilter.allow('foo', 'debug'); | ||
// deny any logs where the module name matches "bar.*", level < 'warn' | ||
// e.g. only let through "warn" and "error" | ||
myFilter.deny(new RegExp('bar.*', 'warn')); | ||
|
||
// now, create a custom pipe | ||
Minilog.pipe(myFilter) | ||
.pipe(Minilog.defaultFormatter) | ||
.pipe(Minilog.defaultBackend); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Type definitions for minilog v2 | ||
// Project: https://github.com/mixu/minilog | ||
// Definitions by: Guido <http://guido.io> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
//These type definitions are not complete, although basic usage should be typed. | ||
interface Minilog { | ||
debug(msg: any): Minilog; | ||
info(msg: any): Minilog; | ||
log(msg: any): Minilog; | ||
warn(msg: any): Minilog; | ||
error(msg: any): Minilog; | ||
} | ||
|
||
declare function Minilog(namespace: string): Minilog; | ||
|
||
declare module Minilog { | ||
export function enable(): Minilog; | ||
export function disable() : Minilog; | ||
export function pipe(dest: any): Transform; | ||
|
||
export var suggest: Filter; | ||
export var backends: Minilog.MinilogBackends; | ||
|
||
export var defaultBackend: any; | ||
export var defaultFormatter: string; | ||
|
||
|
||
export class Filter extends Transform{ | ||
|
||
/** | ||
* Adds an entry to the whitelist | ||
* Returns this filter | ||
*/ | ||
allow(name: any, level?: any): Filter; | ||
/** | ||
* Adds an entry to the blacklist | ||
* Returns this filter | ||
*/ | ||
deny(name: any, level?: any): Filter; | ||
/** | ||
* Empties the whitelist and blacklist | ||
* Returns this filter | ||
*/ | ||
clear(): Filter; | ||
|
||
test(name:any, level:any): boolean; | ||
|
||
/** | ||
* specifies the behavior when a log line doesn't match either the whitelist or the blacklist. | ||
The default is true (= "allow by default") - lines that do not match the whitelist or the blacklist are not filtered (e.g. ). | ||
If you want to flip the default so that lines are filtered unless they are on the whitelist, set this to false (= "deny by default"). | ||
*/ | ||
defaultResult: boolean; | ||
|
||
/** | ||
* controls whether the filter is enabled. Default: true | ||
*/ | ||
enabled: boolean; | ||
} | ||
|
||
|
||
export interface MinilogBackends { | ||
array: any; | ||
browser: any; | ||
console: Console; | ||
localstorage: any; | ||
jQuery: any; | ||
} | ||
|
||
export class Console extends Transform{ | ||
|
||
/** | ||
* List of available formatters | ||
*/ | ||
formatters: string[]; | ||
|
||
//Only available on client | ||
color: Transform; | ||
minilog: Transform; | ||
|
||
//Only available on backend | ||
formatClean: Transform; | ||
formatColor: Transform; | ||
formatNpm: Transform; | ||
formatLearnboost: Transform; | ||
formatMinilog: Transform; | ||
formatWithStack: Transform; | ||
} | ||
|
||
export class Transform { | ||
write(name: any, level: any, args: any): void; | ||
pipe(dest: any): any; | ||
unpipe(from: any): Transform; | ||
mixin(dest: any): void; | ||
} | ||
|
||
} |