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

@firebase-logger/web

v2.0.0

Published

This library allows you to log data from a web or mobile app to a Firebase Realtime Database, to be able to debug and monitor remotely.

Downloads

16

Readme

Firebase logger - Get your (mobile) app logs remotely

This library allows you to log data from a web or mobile app to a Firebase Realtime Database, to be able to debug and monitor remotely.

✨ Features

  • Save logs to a Firebase Realtime Database
  • Logs locally in development mode and remotely in production mode
  • Remote and reactive triggerable log level to prevent logs' flooding
  • Supports firebase SDKs (if you are using ReactNative firebase check @firebase-logger/reactnative)
  • Save logs to a user-specific path, to easily find user's logs

🗒️ Table of Contents

Get started

Install the package

npm i @firebase-logger/core @firebase-logger/web or yarn add @firebase-logger/core @firebase-logger/web

Prepare Firebase

If you already have a Firebase setup in your project, you can skip this part.

  1. Create a Firebase project
  2. Create the database with open rules (you can replace them later on with the example rules in the code samples)
  3. Add an app to your project (get help here)
  4. Get the config and initialize Firebase in your code:
import firebase from "firebase/app";

if (!firebase.apps.length) {
  firebase.initializeApp(FIREBASE_CONFIG);
}
  1. Finally, don't forget to create the logger in database that will contain the log level, for instance, add this to the database:
{
  "loggers": {
    "production": {
      "level": "ERROR"
    }
  }
}

Initialize the logger

import logger from "@firebase-logger/web";

logger.init(process.env.NODE_ENV === 'production');

It will initialize the logger that will log remotely only in production mode, under the logs/main path, using the loggers/main You can re-initialize the logger as soon as the user is authenticated to prevent logging everything in the anonymous path, but in the user-specific path. Learn more in the code samples TODO link

It's ready, log messages

It can be used like the standard console object.

import logger from '@firebase-logger/web'

logger.debug('Hello world');
logger.info('Hello world', 42);
logger.warn({ title: 'Hello', subtitle: 'World' });
logger.error(error);
logger.critical('Something bad happened');

API

init

| Parameter | Required | Default value | Usage | | ------ | ------ | ------ | ------ | | shouldLogRemotely | No | true | Logs to Firebase only if set to true, otherwise, uses the standard console methods like console.error | | getUserId | No | async () => 'anonymous' | A function that returns a promise containing the user identifier as a string or a number | | databaseLoggerPathOrNull | No | 'loggers/main' | The database path to the logger data. Note that this is where the log level is defined (see the sample data) | | databaseLogsCollectionOrNull | false | 'logs/main' | The database path to the logs. It gets created automatically when logging |

log

You can use the following methods to log information:

| Method | Logs when log level is | | ------ | ------ | | debug | DEBUG | | info | DEBUG, INFO | | warn | DEBUG, INFO, WARN | | error | DEBUG, INFO, WARN, ERROR | | critical | DEBUG, INFO, WARN, ERROR, CRITICAL |

All these methods accept as many arguments as you want to provide them.

Samples

const onUserAuthenticated = () => {
  logger.init(
    process.env.NODE_ENV === 'production',
    () => AsyncStorage.getItem('@myApp/userEMail'), // can return a promise
    'loggers/production',
    'logs/production'
  );
}
{
  "rules": {
    "loggers": {
      ".read": true,
      ".write": false
    },
    "logs-dev": {
      ".read": false,
      ".write": true
    },
    "logs-staging": {
      ".read": false,
      ".write": true
    },
    "logs-prod": {
      ".read": false,
      ".write": true
    }
  }
}
{
  "loggers": {
    "dev": {
      "level": "WARN"
    },
    "staging": {
      "level": "CRITICAL"
    },
    "prod": {
      "level": "CRITICAL"
    }
  }
}