LD_PRELOAD=/absolute/path/to/libcoloredstderr.so
COLORED_STDERR_FDS=2,
export LD_PRELOAD COLORED_STDERR_FDS
Last updated 2016-09-11
coloredstderr is a small library which uses LD_PRELOAD to color stderr. It “follows” dups, has minimal performance overhead and can ignore certain binaries (requires /proc).
Like all solutions using LD_PRELOAD it only works with dynamically linked binaries. Statically linked binaries, for example valgrind, are not supported. setuid binaries are also not supported (LD_PRELOAD disabled for security reasons).
Most other existing solutions use a second process which colors its input and pipe stderr to it. However this creates different runtime behaviour resulting in a different ordering of the output. Partial lines (no newline) also often cause problems. coloredstderr handles these cases correctly.
It was inspired by stderred [2]. Similar solutions (using LD_PRELOAD) include:
stderred [1], but doesn’t “follow” dups (I somehow missed it when looking for existing implementations)
stderred [2], but only hooks write()
coloredstderr is licensed under GPL 3 (or later).
C99 compiler (variable length arrays)
dynamic linker/loader which supports LD_PRELOAD (e.g. GNU/Linux’s or FreeBSD’s ld.so)
Tested on GNU/Linux, FreeBSD and Mac OS X (partial support). Should work on all POSIX systems which support LD_PRELOAD (with minor modifications).
Add the following settings to your shell configuration:
LD_PRELOAD=/absolute/path/to/libcoloredstderr.so
COLORED_STDERR_FDS=2,
export LD_PRELOAD COLORED_STDERR_FDS
Also see README in tarball.
Current development happens in the git repository (also browsable as Gitweb):
git clone https://ruderich.org/simon/coloredstderr/coloredstderr.git
version 0.2 (2014-06-22):
Fix hook for GNU’s error_at_line() not exiting if status != 0. If error_one_per_line was used and suppressed a message, then error_at_line() didn’t exit.
Fix race condition when using threads. The fix requires thread-local storage (available on at least GNU/Linux and FreeBSD).
Documentation updates.
Download: coloredstderr-0.2.tar.gz, coloredstderr-0.2.tar.gz.asc
Version 0.1 (2013-12-04):
First release.
Download: coloredstderr-0.1.tar.gz, coloredstderr-0.1.tar.gz.asc
Last updated 2016-09-11