JSPM

winston-react

1.0.0-RC.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 50
  • Score
    100M100P100Q69073F
  • License MIT

A Winston implementation for React

Package Exports

  • winston-react

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (winston-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Winston React

The goal of this bundle is provide a React implementation for [Winston]

Install

npm install winston-react

Usage

in your App.tsx:

import React from 'react';
import winston from 'winston';
import { WinstonProvider } from 'winston-react';

const logger = winston.createLogger({
  // ...
  transports: [
    // ...
    new winston.transports.Console()
  ]
});

const App: React.FC = () => (
  <WinstonProvider logger={logger}>
    <div>
      your awesome application
    </div>
  </WinstonProvider>
);

Using hooks:

import React from 'react';
import { useWinstonLogger } from 'winston-logger';

const Component: React.FC = () => {
  const logger = useWinstonLogger();

  React.useEffect(() => {
    logger.info('your awesome information log!');
  });

  return (
    <div>
      your awesome component
    </div>
  );
};

Using consumer:

import React from 'react';
import { WinstonConsumer } from 'winston-logger';

const Component: React.FC = () => {
  const logger = useWinstonLogger();

  return (
    <WinstonConsumer>
      {(logger) => (
        /* do stuff here */
        <div>
          we have access to the logger!
        </div>
      )}
    </WinstonConsumer>
  );
};