Giter Site home page Giter Site logo

gruffins / birch-rn Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.8 MB

Remote logger used with the Birch logging platform

Home Page: https://birch.ryanfung.com

License: MIT License

Kotlin 19.79% JavaScript 6.35% Ruby 11.28% C 0.31% Objective-C 7.07% Objective-C++ 8.38% Swift 9.97% TypeScript 36.83%

birch-rn's Introduction

Birch

Tests

Simple, lightweight remote logging for React Native.

Sign up for your free account at Birch

BIrch allows you to log to a variety of drains regardless of whether they have a native implementation or not. On top of that, Birch provides the ability to remotely adjust log configurations on any of your apps in production.

Birch can drain to

  • New Relic
  • Datadog
  • Logtail
  • Loggly
  • Elasticsearch
  • Papertrail
  • Logz
  • CloudWatch
  • S3
  • Wasabi
  • Google Cloud Logging
  • A custom webhook

Installation

npm i react-native-birch

Setup

import Birch from 'react-native-birch';
import { useEffect, useState } from 'react';

export default function App() {
  const [userId, setUserId] = useState('');

  useEffect(() => {
    Birch.init({
      apiKey: '',
      publicKey: '',
    });
    
    Birch.setConsole(true);
  }, []);

  useEffect(() => {
    Birch.setIdentifier(userId);
  }, [userId]);
}

Logging

Use the logger as you would with console logs.

Birch.t('trace level message');
Birch.d('debug level message');
Birch.i('info level message');
Birch.w('warn level message');
Birch.e('error level message');

Configuration

Device level configuration is left to the server so you can remotely control it. There are a few things you can control on the client side.

Console

During local development, it is useful to see the logs in the console. These console logs are not useful in production since you cannot read them remotely. The default is false. Setting this will affect console logs on iOS and Logcat on Android.

Birch.setConsole(true);
const useConsole = await Birch.getConsole();

Remote

During local development, it's unlikely that you'll need remote logging. You cna optionally turn it off to minimize your usage on Birch. The default is true.

Birch.setRemote(true);
const remote = await Birch.getRemote()

Level

During local development, you may want to quickly override the server configuration. The default is null which allows teh server to set the remote level. Setting a value will ALWAYS override the server and prevent you from being able to remotely adjust the level.

Birch.setLevel(Level.Trace)
const level = await Birch.getLevel();

Synchronous

During local development, you may want logs to print immediately when you're stepping through with a debugger. To do this, you'll need to use synchronous logging. The default value is false. Synchronous logging is slower since it has to perform the logging inline.

Birch.setSynchronous(true);
const sync = await Birch.getSynchronous();

Debug

When integrating the library, you may be curioius to see the logger at work. By setting debug to true, Birch will log its operations. The default value is false. You should NOT set this to true in a production build.

You will only be able to see these logs in the native iOS console logs or Logcat.

Birch.setDebug(true);
const debug = await Birch.getDebug();

Encryption

We HIGHLY recommend using encryption to encrypt your logs at rest. If you leave out the public encryption key, Birch will save logs on the device in clear text.

An invalid public key will throw an exception.

Identification

You should set an identifier so you can identify the source in the dashboard. If you do not set one, you will only be able to find devices by the assigned uuid via Birch.uuid().

You can also set custom properties on the source that will propagate to all drains.

Birch.setIdentifier('user_id');
Birch.setCustomProperties({
  country: user.country,
});

Opt Out

To comply with different sets of regulations such as GDPR or CCPA, you may be required to allow users to opt out of log collection.

Birch.setOptOut(true);
const optOut = await Birch.getOptOut();

Log Scrubbing

Birch comes preconfigured with an email and password scrubber to ensure sensitive data is NOT logged. Emails and passwords are replaced with [FILTERED] at the logger level so the data never reaches Birch servers.

If you wish to configure additional scrubbers, implement the scrubbing function and initialize the logger with all the scrubbers you want to use.

import { emailScrubber, passwordScrubber } from 'react-native-birch';

function customScrubber(input: string): string {
  return input.replaceAll(REGEX, '[FILTERED]');
}

export default function App() {
  useEffect(() => {
    Birch.init({
      apiKey: '',
      publicKey: '',
      options: {
        scrubbers: [customScrubber, emailScrubber, passwordScrubber],
      }
    })
  }, [])
}

birch-rn's People

Contributors

dependabot[bot] avatar gruffins avatar

Watchers

 avatar

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.