npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-birch

v0.1.0

Published

Simple, lightweight remote logger.

Downloads

2

Readme

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],
      }
    })
  }, [])
}