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

adbkit-logcat-fb

v1.1.0

Published

A Node.js interface for working with Android's logcat output.

Downloads

7

Readme

adbkit-logcat

adbkit-logcat provides a Node.js interface for working with output produced by the Android logcat tool. It takes a log stream (that you must create separately), parses it, and emits log entries in real-time as they occur. Possible use cases include storing logs in a database, forwarding logs via MessagePack, or just advanced filtering.

Getting started

Install via NPM:

npm install --save adbkit-logcat

Note that while adbkit-logcat is written in CoffeeScript, it is compiled to JavaScript before publishing to NPM, which means that you are not required to use CoffeeScript.

Examples

Output all log messages

JavaScript
var logcat = require('adbkit-logcat');
var spawn = require('child_process').spawn;

// Retrieve a binary log stream
var proc = spawn('adb', ['logcat', '-B']);

// Connect logcat to the stream
reader = logcat.readStream(proc.stdout);
reader.on('entry', function(entry) {
  console.log(entry.message);
});

// Make sure we don't leave anything hanging
process.on('exit', function() {
  proc.kill();
});
CoffeeScript
Logcat = require 'adbkit-logcat'
{spawn} = require 'child_process'

# Retrieve a binary log stream
proc = spawn 'adb', ['logcat', '-B']

# Connect logcat to the stream
reader = Logcat.readStream proc.stdout
reader.on 'entry', (entry) ->
  console.log entry.message

# Make sure we don't leave anything hanging
process.on 'exit', ->
  proc.kill()

API

Logcat

logcat.Priority

Exposes Priority. See below for details.

logcat.Reader

Exposes Reader. See below for details.

logcat.readStream(stream[, options])

Creates a logcat reader instance from the provided logcat event Stream. Note that you must create the stream separately.

  • stream The event stream to read.
  • options Optional. The following options are supported:
    • format The format of the stream. Currently, the only supported value is 'binary', which (for example) adb logcat -B produces. Defaults to 'binary'.
    • fixLineFeeds All programs run via the ADB shell transform any '\n' in the output to '\r\n', which breaks binary content. If set, this option reverses the transformation before parsing the stream. Defaults to true.
  • Returns: The Reader instance.

Priority

Constants

The following static properties are available:

  • Priority.UNKNOWN i.e. 0.
  • Priority.DEFAULT i.e. 1. Not available when reading a stream.
  • Priority.VERBOSE i.e. 2.
  • Priority.DEBUG i.e. 3.
  • Priority.INFO i.e. 4.
  • Priority.WARN i.e. 5.
  • Priority.ERROR i.e. 6.
  • Priority.FATAL i.e. 7.
  • Priority.SILENT i.e. 8. Not available when reading a stream.

Priority.fromLetter(letter)

Static method to convert the given letter into a numeric priority. For example, Priority.fromName('d') would return Priority.DEBUG.

  • letter The priority as a String. Any single, case-insensitive character matching the first character of any Priority constant is accepted.
  • Returns: The priority as a Number, or undefined.

Priority.fromName(name)

Static method to convert the given name into a numeric priority. For example, Priority.fromName('debug') (or Priority.fromName('d')) would return Priority.DEBUG.

  • name The priority as a String. Any full, case-insensitive match of the Priority constants is accepted. If no match is found, falls back to Priority.fromLetter().
  • Returns: The priority as a Number, or undefined.

Priority.toLetter(priority)

Static method to convert the numeric priority into its letter representation. For example, Priority.toLetter(Priority.DEBUG) would return 'D'.

  • priority The priority as a Number. Any Priority constant value is accepted.
  • Returns: The priority as a String letter, or undefined.

Priority.toName(priority)

Static method to convert the numeric priority into its full string representation. For example, Priority.toLetter(Priority.DEBUG) would return 'DEBUG'.

  • priority The priority as a Number. Any Priority constant value is accepted.
  • Returns: The priority as a String, or undefined.

Reader

A reader instance, which is an EventEmitter.

Events

The following events are available:

  • error (err) Emitted when an error occurs.
    • err An Error.
  • end Emitted when the stream ends.
  • finish Emitted when the stream finishes.
  • entry (entry) Emitted when the stream finishes.
    • entry A log Entry. See below for details.

constructor([options])

For advanced users. Manually constructs a Reader instance. Useful for testing and/or playing around. Normally you would use logcat.readStream() to create the instance.

  • options See logcat.readStream() for details.
  • Returns: N/A

reader.connect(stream)

For advanced users. When instantiated manually (not via logcat.readStream()), connects the Reader instance to the given stream.

  • stream See logcat.readStream() for details.
  • Returns: The Reader instance.

reader.end()

Convenience method for ending the stream.

  • Returns: The Reader instance.

reader.exclude(tag)

Skip entries with the provided tag. Alias for reader.include(tag, Priority.SILENT). Note that even skipped events have to be parsed so that they can be ignored.

  • tag The tag string to exclude. If '*', works the same as reader.excludeAll().
  • Returns: The Reader instance.

reader.excludeAll()

Skip ALL entries. Alias for reader.includeAll(Priority.SILENT). Any entries you wish to see must be included via include()/includeAll().

  • Returns: The Reader instance.

reader.include(tag[, priority])

Include all entries with the given tag and a priority higher or equal to the given priority.

  • tag The tag string to include. If '*', works the same as reader.includeAll(priority).
  • priority Optional. A lower bound for the priority. Any numeric Priority constant or any String value accepted by Priority.fromName() is accepted. Defaults to Priority.DEBUG.
  • Returns: The Reader instance.

reader.includeAll([priority])

Include all entries with a priority higher or equal to the given priority.

  • tag The tag string to exclude.
  • priority Optional. See reader.include() for details.
  • Returns: The Reader instance.

reader.resetFilters()

Resets all inclusions/exclusions.

  • Returns: The Reader instance.

Entry

A log entry.

Properties

The following properties are available:

  • date Event time as a Date.
  • pid Process ID as a Number.
  • tid Thread ID as a Number.
  • priority Event priority as a Number. You can use logcat.Priority to convert the value into a String.
  • tag Event tag as a String.
  • message Message as a String.

entry.toBinary()

Converts the entry back to the binary log format.

  • Returns: The binary event as a Buffer.

More information

Contributing

See CONTRIBUTING.md.

License

See LICENSE.

Copyright © The OpenSTF Project. All Rights Reserved.