This package has been deprecated

Author message:

I am no longer maintaining this package

@sthom/logging-config-react
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

@sthom/logging-config-react

Logging configuration for Javascript and Typescript.

This exists because the only way to stop my brain from shouting "you need to make a terrible logging library" is to make a terrible logging library.

Make sure to look at the original module: https://www.npmjs.com/package/@sthom/logging-config.

Usage

All exports from @sthom/logging-config are re-exported in @sthom/logging-config-react, so you don't need both in your dependencies.

Basic example:

import useLogger from "@sthom/logging-config-react";

// In your component
const logger = useLogger();

logger.info("Hello world!");

With a tag at the start:

import Logger from "@sthom/logging-config";

const logger = useLogger("MyComponent");

logger.info("Hello world!"); // Logs: [MyComponent] Hello world!

Configuration using context:

import {
  LoggingConfiguration,
  LoggingConfigurationContext
} from "@sthom/logging-config-react";

const config = new LoggingConfiguration("ERROR");

// In your component
<LoggingConfigurationContext value={config}>
  {/* Rest of your app */}
</LoggingConfigurationContext>;

// If your log level changes at run-time, you'll want to memoise the config object.
// This is just a measure to prevent unnecessary re-renders of your app.
const level = /* your logic */;
const config = useMemo(() => new LoggingConfiguration(level), [level]);

Log levels

The following levels, in order of increasing severity, are available:

  • TRACE: logger.trace
  • DEBUG: logger.debug
  • INFO: logger.info
  • WARN: logger.trace
  • ERROR: logger.error
  • FATAL: logger.fatal

Support for custom levels may come in the future.

Readme

Keywords

none

Package Sidebar

Install

npm i @sthom/logging-config-react

Weekly Downloads

148

Version

1.2.2

License

MIT

Unpacked Size

6.48 kB

Total Files

6

Last publish

Collaborators

  • sthom