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

color-logviewer

v1.0.1

Published

Streams log files in a 'tail -F' like way and colors them.

Downloads

6

Readme

color-logviewer

Prints out the tail of a logfile with lines colored depending on the keywords you defined.

color-logviewer colorizing whole lines Default: color-logviewer colorizes whole lines

color-logviewer coloring single words Use the -s switch to colorize single words

Installation

npm install -g color-logviewer

Synopsis

color-logviewer [-n number_of_lines] [-c keyword=color[,keyword=color...]] -s filename

Usage

The following command will display the last 10 lines of logfile.log and start listening for new incoming lines:

color-logviewer logfile.log

All lines will be highlighted according to the default color map, which is defined as follows:

| Keyword | Color | | ------- | ------- | | ERROR | red | | WARN | yellow | | DEBUG | green | | TRACE | blue |

The order of the keywords in the color map determines, which color will be chosen to color a line. For example, as the keyword WARN comes before INFO, DEBUG and TRACE, the WARN keyword and its coloring gets precedence.

Options

  • -n <number-of-lines> By calling the command with the -n switch and a number, you can define how many lines will be displayed initially. (Default: 10)
  • -c <color-map> You can define your own color map by using the -c switch. <color-map> is a String containing key-value pairs, where the key is the word that must occur on a line and the value is a color as defined in https://www.npmjs.com/package/colors#text-colors. (Default: See table above.)
  • -s If you want to colorize only the word itself and not the whole line, just call the function with the -s switch.

An example call with some parameters could look like the following:

color-logviewer -n 15 -c foo=magenta,bar=cyan logfile.log

This will display the last 15 lines of logfile.log, color every line in magenta where the String "foo" occurs and every line where the String "bar" occurs in cyan. And of course it will listen for new lines and color them as well.

Usage inspiration

Depending on your use cases you could create aliases in your .bashrc file to highlight only severity levels you are interested in. For example:

# shorthand command, returns last 20 lines before streaming starts
alias clog="color-logviewer -n 20"

# highlight only lines in which the String "ERROR" occurs
alias clog-error="clog -c ERROR=red"

# highlight only lines in which the String "ERROR" or "WARN" occurs
# (ERROR has precedence as it comes first)
alias clog-warn="clog -c ERROR=red,WARN=yellow"

Troubleshooting

Error: watch log-name.log ENOSPC

As this program makes use of inotify on Linux systems (by using tail which itself uses fs.watch) there is a possibility of an error like the one above.

This is so, because Linux has a limit of how much files can be watched by a single user. Programs like Dropbox or the Grunt watch task make use of the same technique.

However you can increase the amount of watches a single user can have by executing the following command:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

As I am using a Debian based distribution I assume this will work on every other Debian-like system as well.

For Arch Linux the following seems to work, although I did not test it:

Add fs.inotify.max_user_watches=524288 to /etc/sysctl.d/99-sysctl.conf and then execute sysctl --system.

Source: http://stackoverflow.com/questions/16748737/grunt-watch-error-waiting-fatal-error-watch-enospc

History

Changelog

Version 1.0.1 (2016-02-20)

  • Updated README with new pictures and Troubleshooting section.

Version 1.0.0 (2016-01-21)

  • You can now colorize words only instead of the whole line by using the -s switch.
  • As this version seems to be stable enough, I decided to go up to the first major version.

Version 0.5.0 (2016-01-10)

  • Now supports simultaneous view of multiple logfiles via wildcard character (*).

Version 0.4.1 (2016-01-07)

  • Fixed: Program does not work on some Linux installations.

Version 0.4.0 (2015-11-12)

  • Now you can insert blank lines by pressing the return key.
  • The EOL character is now selected depending on the OS.

Version 0.3.1 (2015-11-10)

Better error handling

Version 0.3.0 (2015-11-10)

Display the last n lines before streaming new lines

Version 0.2.2 (2015-11-09)

Better error handling

Version 0.2.1 (2015-11-07)

Fixed typo in readme

Version 0.2.0 (2015-11-07)

Support of custom color maps

Version 0.1.1 (2015-11-07)

MIT license

Version 0.1.0 (2015-11-07)

Initial working version

Todos

  • [ ] Provide help function (-h)
  • [ ] Provide regex pattern instead of simple search for String
  • [ ] Make line endings configurable
  • [ ] Solve encoding issues
  • [x] Add Changelog to readme
  • [x] Enter key should insert blank lines, for a more "tail"-like experience
  • [x] Cross-OS end-of-line characters
  • [x] Create a nice image of the program in action and show it here
  • [x] More reliable error handling
  • [x] Handling of -n 0
  • [x] Before listening for new lines, display the last n lines of the logfile