-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a libdef for the mozlog library (#3615)
- Loading branch information
1 parent
48347c4
commit 8007623
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
definitions/npm/mozlog_v2.2.x/flow_v0.84.x-/mozlog_v2.2.x.js
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,33 @@ | ||
declare module 'mozlog' { | ||
declare type LoggerFunction = (string, mixed) => void; | ||
|
||
declare interface Logger { | ||
trace: LoggerFunction; | ||
verbose: LoggerFunction; | ||
debug: LoggerFunction; | ||
info: LoggerFunction; | ||
warn: LoggerFunction; | ||
error: LoggerFunction; | ||
critical: LoggerFunction; | ||
|
||
// aliases | ||
warning: LoggerFunction; | ||
o_O: LoggerFunction; // alias to warn | ||
O_O: LoggerFunction; // alias to error | ||
} | ||
|
||
declare type LoggerCreator = (string) => Logger; | ||
|
||
declare export default function mozlog(options: string | {| | ||
+app: string, | ||
+fmt?: 'pretty' | 'heka' | void | null, | ||
+debug?: ?boolean, | ||
+level?: | ||
| 'trace' | 'verbose' | 'debug' | 'info' | 'warn' | 'error' | 'critical' | ||
| 'TRACE' | 'VERBOSE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'CRITICAL' | ||
| void | null, | ||
+uncaught?: 'exit' | 'log' | 'ignore' | void | null, | ||
+stream?: stream$Writable | void | null, | ||
+config?: { ... }, | ||
|}): LoggerCreator; | ||
} |
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,117 @@ | ||
import { describe, it } from 'flow-typed-test'; | ||
import mozlog from 'mozlog'; | ||
|
||
describe('mozlog function returns a proper logger', () => { | ||
it('checks arguments of the mozlog factory', () => { | ||
mozlog({ | ||
app: 'app-name', | ||
level: 'verbose', //default is INFO | ||
fmt: 'pretty', //default is 'heka' | ||
uncaught: 'exit', // default is 'log', also available as 'ignore' | ||
debug: true, //default is false | ||
stream: process.stderr //default is process.stdout | ||
}); | ||
mozlog('app-name'); | ||
mozlog({ | ||
app: 'app-name', | ||
}); | ||
mozlog({ | ||
app: 'app-name', | ||
stream: process.stdout, | ||
}); | ||
|
||
// $ExpectError | ||
mozlog(); | ||
// $ExpectError | ||
mozlog('app-name', 'stream'); | ||
// $ExpectError | ||
mozlog(5); | ||
// $ExpectError | ||
mozlog({}) | ||
// $ExpectError | ||
mozlog({ | ||
app: 'app-name', | ||
foo: 'bar' | ||
}); | ||
// $ExpectError | ||
mozlog({ | ||
app: 'app-name', | ||
fmt: 'foo', | ||
}); | ||
// $ExpectError | ||
mozlog({ | ||
app: 'app-name', | ||
level: 'foo', | ||
}); | ||
// $ExpectError | ||
mozlog({ | ||
app: 'app-name', | ||
uncaught: 'foo', | ||
}); | ||
// $ExpectError | ||
mozlog({ | ||
app: 'app-name', | ||
stream: 'foo', | ||
}); | ||
// $ExpectError | ||
mozlog({ | ||
app: 'app-name', | ||
stream: process.stdin, | ||
}); | ||
}); | ||
|
||
it('exposes log methods', () => { | ||
const logCreator = mozlog('app-name'); | ||
const logger = logCreator('module-name'); | ||
|
||
logger.trace('message'); | ||
logger.trace('message', { foo: 'bar' }); | ||
|
||
logger.verbose('message'); | ||
logger.verbose('message', { foo: 'bar' }); | ||
|
||
logger.debug('message'); | ||
logger.debug('message', { foo: 'bar' }); | ||
|
||
logger.info('message'); | ||
logger.info('message', { foo: 'bar' }); | ||
|
||
logger.warn('message'); | ||
logger.warn('message', { foo: 'bar' }); | ||
|
||
logger.error('message'); | ||
logger.error('message', { foo: 'bar' }); | ||
|
||
logger.critical('message'); | ||
logger.critical('message', { foo: 'bar' }); | ||
|
||
logger.warning('message'); | ||
logger.warning('message', { foo: 'bar' }); | ||
|
||
logger.o_O('message'); | ||
logger.o_O('message', { foo: 'bar' }); | ||
|
||
logger.O_O('message'); | ||
logger.O_O('message', { foo: 'bar' }); | ||
|
||
// loggers also accept other types | ||
logger.warn('message', 42); | ||
logger.warn('message', 'foo'); | ||
|
||
// $ExpectError | ||
logger.warn(); | ||
|
||
// $ExpectError | ||
logger.warn(42); | ||
|
||
// $ExpectError: This is accepted by intel, but mozlog forbids this explicitely. | ||
logger.warn('message', 'foo', 'bar'); | ||
}); | ||
|
||
it('does not expose global types', () => { | ||
const logCreator = mozlog('app-name'); | ||
|
||
// $ExpectError | ||
(logCreator: LoggerCreator); | ||
}); | ||
}); |