Brolog is Logger for Angular in Browser like Npmlog.
-
Support TypeScript.
-
Support Angular 4 & SystemJS. (brolog-angular-demo project git repository)
-
Support show real line number in browser console.
What I really get frustrated by is that I cannot wrap console.* and preserve line numbers
We enabled this in Chrome DevTools via blackboxing a bit ago.
-
Can be used by nodejs if you like. (nodejs example here)
Here's two example:
- First example to demo easy to use in browser, and how it looks like npmlog.
- Second example to demo intergrate with angular DI & SystemJS.
You can enable Brolog in your page by simple add the following script
tag.
FIXME: might broken on v1.0
<script src="//unpkg.com/brolog"></script>
<html>
<head>
<script src="//unpkg.com/brolog"></script>
</head>
<body>
<h1>Brolog in Browser Demo</h1>
<script>
var log = Brolog.instance('verbose')
log.info('Test', '123 info message')
log.verbose('Test', '123 verbose message')
log.silly('Test', '123 silly message')
</script>
</body>
</html>
Link: Brolog Live demo on Plunker
Brolog
is writen mainly for act as a logger with Angular. Here's how to Inject Brolog in Angular.
- install brolog
$ npm install brolog --save
- setup SystemJS
System.config({
map: {
brolog: 'node_modules/brolog/dist/brolog.js'
}
})
- import
import { Brolog } from 'brolog'
- inject to @NgModule
providers: [
{
provide: Brolog,
useFactory: function brologFactory() { return Brolog.instance('silly') },
},
]
- inject to constructor
class LogApp {
constructor(
private log: Brolog
) {}
}
- log
class LogApp {
testLog() {
this.log.verbose('Brolog', 'test log %d', 123)
// this will log to browser console
}
}
More details, please see the brolog-angular-demo
git repository here.
Link: Brolog ♥ Angular Live demo on Plunker
var log = require('brolog')
// additional stuff ---------------------------+
// message ----------+ |
// prefix ----+ | |
// level -+ | | |
// v v v v
log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
- {String} 'silent' | 'error' | 'warn' | 'info' | 'verbose' | 'silly'
The level to display logs at. Any logs at or above this level will be
displayed. The special level silent
will prevent anything from being
displayed ever.
level
{String} The level to emit the message atprefix
{String} A string prefix. Set to "" to skip.message...
Arguments toutil.format
Emit a log message at the specified level.
For example,
- log.silly(prefix, message, ...)
- log.verbose(prefix, message, ...)
- log.info(prefix, message, ...)
- log.warn(prefix, message, ...)
- log.error(prefix, message, ...)
Brolog comes with well test suit to ensure the behaviour is expected.
$ npm run unit
Unite Test Suite: link
$ npm run e2e
End to End Test Suite: link
P.S. runing E2E test is based on brolog demo project: git repository
Compatible with AOT & WebPack with Angular v4.0
- Rewrite from JavaScript to TypeScript
- Add UMD/AMD/System Module support
- added timestamp to log output
- fix CI back to work
- added CD to auto deploy source code to NPM after passed CI
- added End to End test with Angular
- supported include by
script
tag - full support unpkg.com
- added Unit Test
- supported Angular Dependience Injection
- supported show real line number by set blackbox
- added TypeScript definition file
- supported work with SystemJS & Angular