Brolog is Logger for Angular in Browser like Npmlog.
<script src='//unpkg.com/brolog'></script>
)log.verbose('Brolog', 'Hello, %s', 'world!'')
)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.
Brolog implementes Loggable:
interface Loggable {
error (moduleName: string, message: string, ...args: any[]): void
warn (moduleName: string, message: string, ...args: any[]): void
info (moduleName: string, message: string, ...args: any[]): void
verbose (moduleName: string, message: string, ...args: any[]): void
silly (moduleName: string, message: string, ...args: any[]): void
}
You can import and use it by:
import { Loggable } from 'brolog'
Here's two example:
You can enable Brolog in your page by simple add the following script
tag.
<script src="https://github.com/huan/brolog/raw/main//unpkg.com/brolog"></script>
<html>
<head>
<script src="https://github.com/huan/brolog/raw/main//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(should not appear)')
</script>
</body>
</html>
Link: Brolog Live demo
Brolog
is written 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/bundles/brolog.js'
}
})
import
import { Brolog } from 'brolog'
inject to @NgModule
providers: [
Brolog,
]
inject to constructor
class LogApp {
constructor(
private log: Brolog
) {}
}
log
class LogApp {
testLog() {
this.log.verbose('Brolog', 'test log:%s', 123)
// this will log to browser console
}
}
More details, please see the brolog-angular-demo
git repository at here.
Link: Brolog ♥ Angular Live demo
Get a out-of-the-box log
instance to use it directly.
import { log } from 'brolog'
If fhe environment variable BROLOG_LEVEL
is set, that will be used to set log.level() for the global Brolog instance log
.
import { Brolog } from 'brolog'
const log = new Brolog()
// additional stuff ---------------------------+
// message ----------+ |
// prefix ----+ | |
// level -+ | | |
// v v v v
log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
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 to util.format
Emit a log message at the specified level.
For example,
BROLOG_PREFIX
Example:
Shell
BROLOG_PREFIX="(Contact|Puppet)" node wechaty.js
This will equals to set by code API:
log.prefix(/^(Contact|Puppet)$/)
Brolog comes with well test suit to ensure the behavior is expected.
$ npm run unit
...
Unite Test Suite: link
$ npm run e2e
...
End to End Test Suite: link
P.S. running E2E test is based on brolog demo project: git repository
Loggable
interfacerollup
behavior change. (#69)BROLOG_PREFIX
to set the prefix
filter of global log
instance.BROLOG_PREFIX
to set the prefix
filter of global log
instance.brolog@next
when the minor version in SemVer is odd(development release).BROLOG_LEVEL
to set the loglevel of global log
instance.BROLOG_LEVEL
to set the loglevel of global log
instance.Brolog.enableLogging()
method for:
false
for disable loggingtrue
for enable loggingprintTextFunc: (text: string)
for enable logging to a function.Compatible with AOT & WebPack with Angular v4
enableLogging()
to get/set loggerscript
tag