Giter Site home page Giter Site logo

react-native-device-log's Introduction

react-native-device-log

Description

A debug-view that prints your debug-messages in a neat listview. Supports different levels of log-messages, complex data (With pretty printing), timers for measuring perf and much more. Adheres to a simple, async, protocol for saving messages where you can plug in your own adapter, or use AsyncStorage from React Native to persist log-messages between session. (Or just use simple session in-memory storage).

Also tracks Connectivity of Device and App-State-changes (Background, Idle, Active).

Will also, if you choose to (flag), track exceptions in your app and in React Native and log linenumbers and methods so you can track crashes in production.

Configure how many messages that should be rendered in the ListView and how many messages should be persisted. All built to be efficent and fast.

Install:

npm install react-native-device-log --save

Example:

/**
 * Sample React Native App width react-native-device-log
 * https://github.com/facebook/react-native
 */
import React, { Component } from 'react';
import  {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  AsyncStorage
} from 'react-native';

//The device-log contains the public api that you will use in your app.
//The LogView is the GUI/Log-list that you can render at desired location //in your app:

import deviceLog, {LogView, InMemoryAdapter} from 'react-native-device-log';

//Call init and set a custom adapter that implements the interface of
//AsyncStorage: getItem, removeItem, setItem.
//By default the log uses a in-memory object, in this example we
//explicitly set the log to use the persistent AsyncStorage instead:

deviceLog.init(AsyncStorage /* You can send new InMemoryAdapter() if you do not want to persist here*/
,{
  //Options (all optional):
  logToConsole : false, //Send logs to console as well as device-log
  logRNErrors : true, // Will pick up RN-errors and send them to the device log
  maxNumberToRender : 2000, // 0 or undefined == unlimited
  maxNumberToPersist : 2000 // 0 or undefined == unlimited
}).then(() => {

  //When the deviceLog has been initialized we can clear it if we want to:
  //deviceLog.clear();

});

//The device-log contains a timer for measuring performance:
deviceLog.startTimer('start-up');

class AwesomeProject extends Component {

  componentDidMount() {
    //Print the current time of the above timer:
    deviceLog.logTime('start-up');

    //Available log messages:
    deviceLog.log("Hello", "world!");
    deviceLog.info("A info message");
    deviceLog.debug("A debug message", {test: "test"});
    deviceLog.success("A success message");

    //Print the current time of the above timer again:
    deviceLog.logTime('start-up');

    //Later stop and remove the timer:
    //Will not print anything.
    deviceLog.stopTimer('start-up');

    setTimeout(() => {
      deviceLog.error("I'm late!!");
    }, 3000);
  }

  render() {
    /*
    inverted: will write the log inverted.
    multiExpanded: means that multiple logmessages
    that are longer then one row can be expanded simultaneously
    timeStampFormat: moment format for timeStamp
    */
    return (
      <LogView inverted={false} multiExpanded={true} timeStampFormat='HH:mm:ss'></LogView>
    );
  }
}

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

react-native-device-log's People

Contributors

alexpanov avatar christianbach avatar ijzerenhein avatar olofd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-device-log's Issues

Add plus attribute to stored object

Hello!

First of all, thanks to sharing this package.
I'm planning to use it in an app to store user activities and errors.
I'd like to send the stored logs back to the server. Because the app works offline too, i have to be able to label the logs which failed to get back to the server or happened offline.

Do you think that is a good feature to be able to bind data to the log?
Something like this:
deviceLog.info('Order failed', { forwarded: { false } })

If so, I can try to make a PR for this.

setState() called after unmount

This line is being called after unmount. It's probably harmless, but might be something to clean up.

Warning: setState(...): Can only update a mounted or mounting component. This 
usually means you called setState() on an unmounted component. This is a no-op.
Please check the code for the DebugView component.

Logging in production?

I don't seem to be able to see logs when running on TestFlight builds - is there anything to be configured in order to see the logs on a production build?

AsyncStorage persistence not working suddenly

I don't expect a PR to address this or anything, but @olofd do you have any ideas what I can check? I tried clearing and pausing the logs, and I tried switching to InMemoryAdapter and then back to AsyncStorage, but no luck in any case unfortunately.

My setup looks like this:

deviceLog
  .init(
    AsyncStorage,
    // new InMemoryAdapter(),
    {
      // Options (all optional):
      logToConsole: false, // Send logs to console as well as device-log
      logRNErrors: true, // Will pick up RN-errors and send them to the device log
      maxNumberToRender: 0, // 0 or undefined == unlimited
      maxNumberToPersist: 4000, // 0 or undefined == unlimited
    }
  )
  .then(() => {});

Super express must either be null or a function, not undefined

relevant code:

import React, { Component } from 'react';
import deviceLog, {LogView} from 'react-native-device-log';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  AsyncStorage,
} from 'react-native';

deviceLog.init(AsyncStorage, { logToConsole : true }).then(() => {
  //When the deviceLog has been initialized we can clear it if we want to:
  //deviceLog.clear();
});

and i debug and found the single line

import deviceLog, {LogView} from 'react-native-device-log';

caused the exception

Maybe it's the version issue:?

node -v

v6.2.0

react-native --version

react-native-cli: 0.2.0
react-native: 0.26.0

version of this repo:
"react-native-device-log": "0.0.7"

Nice log utility if it could work, please fix it!

Undefined type on handling NetInfo event

My app using ReactNative 0.47 and encounter the following error on importing deviceLog:

"Cannot read property 'toUpperCase' of undefined'
at line 69 of debug-service.js

This happens because connectionInfo.type is undefined. I've workarounded by checking !type before the check of type === 'none'
if (!type || type === "none") {...}

keyboardShouldPersistTaps={true/false} is deprecated

Hi,

I upgraded to React Native 0.40.0 and got the following warning:

image

I know it is not a big deal, but it would be nice to get rid of that warning. It seems like an easy fix.

Please let me know if you have any questions.

Thank you

The type is undefined

NetInfo.addEventListener(
"connectionChange",
this._handleConnectivityTypeChange.bind(this)
);
_handleConnectivityTypeChange(connectionInfo) {
let { type, effectiveType } = connectionInfo;
if (type === "none") {
this.hasBeenDisconnected = true;
this.seperator(DISCONNECTED FROM INTERNET);
} else {
const buildConnectionString = () => {
return ${type.toUpperCase()}${effectiveType === "unknown" ? "" : - ${effectiveType}};
};
if (this.hasBeenDisconnected) {
this.seperator(
[NETINFO] RECONNECTED TO ${buildConnectionString()}
);
} else {
if (this.connectionHasBeenEstablished) {
this.seperator(
[NETINFO] CHANGED TO ${buildConnectionString()}
);
} else {
this.seperator(
[NETINFO] CONNECTION TO ${buildConnectionString()}
);
}
}
}
this.connectionHasBeenEstablished = true;
}

Hi olofd, These code is in debug-service.js and connectionInfo is just a string like 'wifi'.

Here is my environemnt:

System
platform darwin
arch x64
cpu 4 cores Intel(R) Core(TM) i5-3427U CPU @ 1.80GHz
directory /Users/hank/Documents/workspace/steps-app

JavaScript
node 8.1.3 /usr/local/bin/node
npm 5.0.3 /usr/local/bin/npm
yarn 0.18.1 /usr/local/bin/yarn

React Native
react-native-cli 2.0.1
app rn version 0.46.4

Ignite
ignite 2.0.0 /usr/local/bin/ignite

Android
java 1.8.0_31 /usr/bin/java
android home - undefined

iOS
xcode 8.3.3

Can you help us to look at this bug?

Thanks,
Hank

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.