1.1.0 • Published 1 year ago

@nivalit/web-logger-react v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Web Logger React Context

Small React package to create a facade that communicates with WebLogger service. Provides useLogger hook that allow user to send diagnostic data and map them to GELF format.

🧭 Usage

npm --save @nivalit/web-logger-react

Add Provider to your app root component:

function App() {
  return (
    <LoggerProvider
      type="EXTERNAL"
      options={{ host: "https://logger.acme.com:9000", logLevel: "WARNING" }}
    >
      <h1>Web Logger</h1>
    </LoggerProvider>
  );
}

Use in any your component by context hook:

function Children() {

  logger = useLogger()

  const createPost = (id: string) => {
    try {
      logger.debug(`Post - Create new with id=${id}`)
      ...
    } catch(e) {
      logger.error(`Post - Failed to create post with id=${id}`, e.stack)
    }
  }
}

You can open the Index.tsx file to see how it can be implemented

💻 Developer environment

Use src directory to test how LoggerContext works. Finally the lib directory is compiled and packed to es and umd formats.

📑 Documentation

LoggerProvider

PropertyValue TypeDescription
typeCONSOLE | EXTERNALDefine which logger service use (default value: "CONSOLE")
disablebooleanIf true disable all logs in within provider
optionsLoggerOptionsConfiguration of GELF host and log level threshold
childrenReactNode (required)Provider child component

useLogger

MethodArguments
debugmessage: string
infomessage: string
noticemessage: string
warnmessage: string
errormessage: string, stackTrace?: string
criticalmessage: string
alertmessage: string
1.1.0

1 year ago

1.0.0

1 year ago

0.0.1

1 year ago