A logger plugin that can handle logging both server side and client side. On the server it uses winston directly. On the client, it batches logs and sends them via network to the server at set intervals.
Depends on fusion-plugin-universal-events.
yarn add fusion-plugin-universal-loggerimport {LoggerToken} from 'fusion-tokens';
// ...
app.middleware({logger: LoggerToken}, ({logger}) => {
return (ctx, next) => {
if (__NODE__) logger.info(`Received request at ${ctx.url}`);
else logger.info(`Pageload at ${ctx.url}`);
return next();
};
});import App from 'fusion-core';
import winston from 'winston';
import UniversalEvents from 'fusion-plugin-universal-events';
import UniversalLogger, {
UniversalLoggerConfigToken,
} from 'fusion-plugin-universal-logger';
export default () => {
const app = new App(<div>Hello</div>);
app.register(UniversalEventsToken, UniversalEvents);
app.register(LoggerToken, UniversalLogger);
if (__NODE__) {
// optional winston configuration
const config = {
transports: [new winston.transports.File({filename: 'logs.log'})],
};
app.register(UniversalLoggerConfigToken, config);
}
return app;
};import UniversalLogger from 'fusion-plugin-universal-logger';The universal logger plugin. Typically it should be registered to the LoggerToken. Provides the logger service api
import {LoggerToken} from 'fusion-tokens';fusion-plugin-universal-logger conforms to the standard logger api designated by the LoggerToken from the fusion-tokens library, and is most commonly registered with this token.
import {UniversalEventsToken} from 'fusion-plugin-universal-events';An event emitter plugin, such as the one provided by fusion-plugin-universal-events. Required.
import {UniversalLoggerConfigToken} from 'fusion-plugin-universal-logger';A Winston configuration object. Optional. Server-side only.
logger.log(level, ...args);level: string- Valid levels:'error','warn','info','verbose','debug','silly'args: [string]
logger.error(...args);args: [string]
logger.warn(...args);args: [string]
logger.info(...args);args: [string]
logger.verbose(...args);args: [string]
logger.debug(...args);args: [string]
logger.silly(...args);args: [string]