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

@timberio/node

v0.35.0

Published

Timber.io - Node.js logger

Downloads

3,094

Readme

🌲 Timber - Node.js logging

Beta: Ready for testing Speed: Blazing ISC License

New to Timber? Here's a low-down on logging in Javascript.

@timberio/node

This NPM library is for logging in Node.js.

If you have a universal or client-side app that requires logging in the browser, check out @timberio/browser or @timberio/js (which combines the two packages.)

Here's how to get started:

Installation

Install the package directly from NPM:

npm i @timberio/node

Importing

In ES6/Typescript, import the Timber class:

import { Timber } from "@timberio/node";

For CommonJS, require the package:

const { Timber } = require("@timberio/node");

Creating a client

Simply pass your Timber.io organization API + source keys as parameters to a new Timber instance (you can grab both from the Timber.io console):

const timber = new Timber("timber-organization-key", "timber-source-key");

Documentation

This Node.js library extends @timberio/core, which provides a simple API for logging, adding middleware and more.

Visit the relevant readme section for more info/how-to:

Streaming

In addition to .log|debug|info|warn|error() returning a Promise, the Node.js logger offers a .pipe() function for piping successfully synchronized logs to any writable stream.

This makes it trivial to additionally save logs to a file, stream logs over the network, or interface with other loggers that accept streamed data.

Here's a simple example of saving logs to a logs.txt file:

// Import the Node.js `fs` lib
import * as fs from "fs";

// Import the Node.js Timber library
import { Timber } from "@timberio/node";

// Open a writable stream to `logs.txt`
const logsTxt = fs.createWriteStream("./logs.txt");

// Create a new Timber instance, and pipe output to `logs.txt`
const timber = new Timber("timber-organization-key", "timber-source-key");
timber.pipe(logsTxt);

// When you next log, `logs.txt` will get a JSON string copy
timber.log("This will also show up in logs.txt");

Streamed logs passed to your write stream's .write() function will be JSON strings in the format of type ITimberLog, and always contain exactly one complete log after it has been transformed by middleware and synced with Timber.io.

e.g:

{"dt":"2018-12-29T08:38:33.272Z","level":"info","message":"message 1"}

If you want to further process logs in your stream, remember to JSON.parse(chunk.toString()) the written 'chunk', to turn it back into an ITimberLog object.

Calls to .pipe() will return the passed writable stream, allowing you to chain multiple .pipe() operations or access any other stream function:

// Import a 'pass-through' stream, to prove it works
import { PassThrough } from "stream";

// This stream won't do anything, except copy input -> output
const passThroughStream = new PassThrough();

// Passing to multiple streams works...
timber.pipe(passThroughStream).pipe(logsTxt);

LICENSE

ISC