Open Download opened 5 years ago
So I noticed an issue... when context would be created with an options object but without a log option set, it would not have used console... Fixed that, squashed commits then force-pushed. I think it should be ok now... Let me know if you need more changes.
EDIT: Mmm I messed up the commit message.. it is duplicated... anyway maybe you can live with it?
Looks good. Can you also make the logger a global?
Hi @valotas
Can you describe how you would make it global?
And would it be an idea to just use https://npmjs.com/package/ulog ?
I wrote this package one day to solve 'the logger problem' for all my packages in one go. It is optimized to be very small (~1kB) and very configurable. Using ulog I would implement the logging like this:
import ulog from "ulog";
const log = ulog('preact-context')
// ...
log.warn('message');
The library user can then use ulog to configure the logging. E.g. setting a key in localStorage log=info
would enable info logging throughout the codebase. Setting debug=preact-context
would enable debug mode for all loggers named 'preact-context'
etc. It also allows injecting formatters etc.
Of course that would mean an extra dependency...
@valotas Can you share your ideas for the logging?
Hi @Download, excuse me for the late reply. I would export an options = { warn: console.warn }
object. This is the preact way, so I believe it is good to follow the same pattern
Log
with methodwarn
Options
with fields:providerOptional
:Boolean
log
:Log
noopEmitter
with emitter factorycreateDefaultEmitter
Options
tocreateDefaultEmitter
Options
tocreateContext
providerOptional
option tofalse
log
option toconsole
if it existscreateContext
creates adefaultEmitter
by callingcreateDefaultEmitter
and passing the options to itdefaultEmitter
when there is no emitterconsole.warn
with calls tolog.warn
Fixes #24