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

homey-betterstack

v0.3.5

Published

A betterstack logger for Homey

Downloads

38

Readme

Homey - Betterstack

📣 Logtail is now part of Better Stack. Learn more ⇗

Better Stack dashboard

Introduction

This package provides integration between your Homey app and Betterstack logging service. By using this package, you can easily log events, errors, and other information from your Homey app to Betterstack for monitoring and analysis.

Setup

  1. Create an account and project on Betterstack.
  2. Obtain the source_token provided by Betterstack.
  3. Add the source_token as HOMEY_BETTERSTACK_TOKEN in your env.json file.

Installation

You can install the package via npm:

npm install homey-betterstack

or

yarn add homey-betterstack

Usage

Import the package

const HomeyLog = require("homey-betterstack");

Extend the app class

Edit the app class to extend HomeyLog:

//From:
class App extends Homey.App {
// To
class App extends HomeyLog {

Logging from app.js

Use this.log or this.error etc within your app.js:

this.trace("Event occurred");
this.debug("Event occurred");
this.info("Event occurred"); // log is the same as info
this.log("Event occurred"); // log is the same as info
this.warn("Warning occurred", error);
this.error("Error occurred", error);
this.fatal("Fatal error occurred", error);

Logging from devices and drivers

Use this.homey.app.log etc from within your devices and drivers:

this.homey.app.trace("Event occurred in device/driver");
this.homey.app.debug("Event occurred in device/driver");
this.homey.app.log("Event occurred in device/driver"); // log is the same as info
this.homey.app.log("Event occurred in device/driver"); // log is the same as info
this.homey.app.warn("Warning occurred in device/driver", error);
this.homey.app.error("Error occurred in device/driver", error);
this.homey.app.fatal("Fatal error occurred in device/driver", error);

Note:

Make sure to remove any log functions in your app as they will overwrite the log functionality of Homey-Betterstack

Not allowed ❌ :

    log() {
        console.log.bind(this, '[log]').apply(this, arguments);
    }

    error() {
        console.error.bind(this, '[error]').apply(this, arguments);
    }

Example

class App extends HomeyLog {
  async onInit() {
    try {
      this.log(`${Homey.manifest.id} - ${Homey.manifest.version} started...`);
    } catch (error) {
      this.homey.app.log(error);
    }
  }
}

module.exports = App;

Result

In the terminal:

[info] com.test.app - 0.0.1 started...

In Betterstack:

Configuration

Change Log Level

It is possible to alter the loglevels and change the enable/disable the output to console/betterstack. Add the following to your Homey app env.json:

    "HOMEY_BETTERSTACK_CONFIG": {
        "console_enabled": "1",
        "publish_enabled": "1",
        "console_level": "info",
        "publish_level": "info"
    }

Above values are also the default values of the app.

Log Levels

The following log levels are available:

    trace: 6,
    debug: 5,
    info: 4,
    warn: 3,
    error: 2,
    fatal: 1

E.G: When setting the level to warn everything below warn will be logged.