redux-loggerwith more features
An attempt at implementing
Typescript with more features!
redux-logger is not very active.
IMHO, there's a lot of disgusting stuff in there :3
redux-logger, you can fully customize how logging is performed.
redux-logger only provides 1 customization point : the options.
This library exposes 2 customization points : the printer and the options.
Therefore, you can tailor logging to your exact needs.
For example, the default logging provided in
redux-logger does not really work outside of
If you look at our example in customizedLogger, you can instead just print normally without any formatting.
This library is implemented entirely using
TypeScript which makes maintaining and fixing this library much, much easier.
This is just my opinion, but there's a lot of dubious stuff in the
For example, it performs indirection unnecessarily.
However, I'll let you be the judge of that :3
To use this library, lets look at the simplest way we can create a logging middleware.
// An empty option class// Finally apply the middleware.
Notice that this library does not actually perform any logging.
However, we do provide sane defaults that works really well on the web that is very similar to
However, because you are not bound to our implementation, you can do whatever you want!
Quite scary, but lets take a look at it slowly.
Sis simply the full state of your application i.e. it is the root reducer of your Redux.
Eis the error type that you have, if you don't care, just set it to
Ois the option type that you can use to configure how printing is performed. Notice that the type
Ois not bounded; you are free to implement it however you want!
In the example above, its a empty struct because there are no options. To see a robust and powerful example of options, see our implementation of the defaultWebLogger
O refers to state, error and options respectively.
logErrordetermines if we are logging exceptions.
logPredicatedetermines if we should log a particular action or not.
printLogis the actual place where you are free to log however you want.
printLog accepts 2 arguments:
LogEntry<S, E> and
This is the type signature for the former.
actionis the current action we are performing.
erroris a maybe type that may contain error if you set
logErrorto true and an error actually occurs.
startedTimeis the date/time when this particular entry is logged.
tookis the time taken to calculate the next state.
prevStateis the state before redux calculations.
nextStateis the state after redux calculations.