README
anylogger-debug 1.0.3
Anylogger adapter for debug
.
What is this?
This is an anylogger adapter for debug.
This package is meant for application projects that are using libraries using
anylogger
. By including this adapter in your project, all libraries using
anylogger
will automatically start to use debug
as their logging framework.
Download
- anylogger-debug.js (fully commented source ~5kB)
- anylogger-debug.min.js (minified 133 bytes, gzipped ~121 bytes)
CDN
index.html
<script src="https://unpkg.com/anylogger@1.0.6/anylogger.min.js"></script>
<script src="https://unpkg.com/anylogger-debug@1.0.3/browserified-debug-4.1.1.min.js"></script>
<script src="https://unpkg.com/anylogger-debug@1.0.3/anylogger-debug.min.js"></script>
<script>(function(){ // IIFE
var log = anylogger('index.html')
log.info('Logging is simple!')
// to see logging, enable it, e.g.:
// localStorage.setItem('debug', '*')
})()</script>
Install
Install this adapter, as well as both anylogger
and debug
:
npm install --save anylogger-debug anylogger debug
Include in your application project
This package is meant for application projects. If you are writing a library to
be NPM installed into some other project, most likely you should not include
any adapter, but instead just use anylogger
directly.
The anylogger-debug
adapter will modify the anylogger
factory in such a way
that the loggers it creates will be logging to debug
.
When using
debug
, all logging is supressed by default. As such, you should make sure to activate debug mode with the environment variable or localStorage key as usual before expecting to see any output.
To activate the adapter, include it in your application entry point.
Require
main.js
require('anylogger-debug')
Import
main.js
import 'anylogger-debug'
Logging in the application project
In your application module code, only use anylogger to stay framework independent:
my-module.js
import anylogger from 'anylogger'
const log = anylogger('my-module')
log('Logging is simple!')
This is helpful if you ever decide to factor out the application module into a separate library.
log configuration in the application project
Because anylogger
is simply using debug
below the surface, you can use
all the normal configuration mechanisms available for debug
.
If you need to control log settings programmatically, just import debug
and
use it directly:
main.js
// ...
import debug from 'debug'
debug.enable('my-module')
// ...
I suggest using
debug
's build-in configuration mechanism via environment variables and localstorage lookup keys instead of doing it from code.
Issues
Add an issue in this project's issue tracker to let me know of any problems you find, or questions you may have.
Copyright
© 2020 by Stijn de Witt. Some rights reserved.
License
Licensed under the MIT Open Source license.
gzip-size
The GZIP algorithm is available in different flavours and with different possible compression settings. The sizes quoted in this README have been measured using gzip-size by Sindre Sorhus, your mileage may vary.