1.0.3 • Published 7 years ago

react-loggly v1.0.3

Weekly downloads
51
License
MIT
Repository
github
Last release
7 years ago

React Loggly Component

Easily log to loggly from inside your react application.

Getting Started

Install React-Loggly using npm:

npm install --save react-loggly

At the top of your application, or at the top of the tree where you want to do your logging, add ReactLoggly

import ReactLoggly from 'react-loggly';
...
render(){
    return (
        <ReactLoggly
            token={this.state.token}
        >
         <App>
        </ReactLoggly>
    );
}

Then in each component you want to log from, accept the context type: logger

class MyComponent extends React.Component{
  static contextTypes = {
    logger: PropTypes.func,
  };

  render(){
    return (
        <button onClick={() => {
           this.context.logger("Logging from my component");
        }}
        >
            Log
        </button>
    );
  }
}

Props

  • token: Loggly API token
  • logFromConsole: When true, capture console output and send it to loggly
  • logToConsole: When true, echo all log messages sent to loggly to the console too
  • tags: Array of tags to log with the message.

Log(data)

Expects data to be a string or an object, which will be send to loggly.