@nerrewton/spring_react_logger
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Spring React Logger

This is a package for capturing error messages and tracking their origin, we include at first Sentry as a third party company for logging purposes but it can support others APIs.

Installation

npm install @nerrewton/spring_react_logger

Usage for React

import React from "react"
import ReactDOM from 'react-dom'
import { init as initSpringLogger, ReactSentryLogger } from "@nerrewton/spring_react_logger"
import App from './App';

// SpringLogger inicialization for React Sentry API
initSpringLogger( new ReactSentryLogger("http:<url external API>") )

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
import React from "react"
import { write as writeSpringLogger } from "@nerrewton/spring_react_logger"

const App = () => {
    const errorFunction = () => {
        throw new Error("This is my first Error!") // This error will be captured by default
    }

    const handleClick = () => {
        try{
            throw new Error("This is my first info Error!")
        }catch(e){
            writeSpringLogger("info", e) // This is an example of trigger an error manually
        }
    }

    return (
        <button type="button" className="btnErrorClass" onClick={ errorFunction }>Break the world</button>
        <button type="button" className="btnInfoClass" onClick={ handleClick }>Trigger an info error</button>
    )
}

export default App;

Readme

Keywords

Package Sidebar

Install

npm i @nerrewton/spring_react_logger

Weekly Downloads

16

Version

2.0.0

License

ISC

Unpacked Size

171 kB

Total Files

27

Last publish

Collaborators

  • nerrewton