Menu

Installing

Paul Gover

Install logcolourer by:

  1. downloading the package;
  2. compiling the source code;
  3. installing the resulting program;
  4. creating a custom syslog-ng template;
  5. piping log streams through logcolourer; and optionally
  6. customizing the colours.

Downloading the package

Download it from sourceforge, and unpack it:

tar -zxvf logcolourer-1.0.tgz

Compiling the source code

logcolourer is a CMake project. To compile it, enter the logcolourer-1.0 directory, and check that in turn contains an empty build directory. Enter that directory, and run cmake ../ and then make. The package comes with an empty build directory to keep things simple:

cd logcolourer-1.0
cd build
cmake ../
make

Installing the resulting program

As root, from the logcolourer-1.0/build directory, run * make install*:

su -
cd /home/<user>/logcolourer-1.0/build
make install

This installs the program as /usr/local/bin/logcolourer, the README as /usr/local/share/doc/logcolourer/README, the man page as /usr/local/share/man/en/man.1/logcolourer.1.man, and the configuration file as /usr/local/etc/logcolourer.conf.

Creating a custom syslog-ng template

Create a template which includes the severity level as the first character in each logged line using a line such as the following in syslog-ng.conf:

template colouredTemplate { template("$LEVEL_NUM $S_DATE $MSGHDR$MSG\n"); }

Download the syslog-ng manual from the Balabit web site to find out more about templates and configuring syslog-ng.

Piping log streams through logcolourer

logcolourer is a UNIX pipe - it reads messages from stdin and writes the lines containing the ANSI escape characters to stdout. syslog-ng supports a program parameter to its destination command to pipe messages to a program such as logcolourer. Use it by including a line such as the following in syslog-ng.conf. The following lines in syslog-ng.conf will send coloured output to TTY12:

destination consoleDestination {
    program("logcolourer >/dev/tty12" template(colouredTemplate));
};

The following lines add coloured output to the file /var/log/coloured:

destination colouredDestination {
    program("/usr/local/bin/logcolourer >>/var/log/coloured"
        template(colouredTemplate));
};

Sample /etc/syslog-ng/syslog-ng.conf

The file below creates 3 logs, a coloured log for messages at or above the "notice" level to TTY12, a coloured log for messages at or above the "info" level to /var/log/coloured and an unfiltered uncoloured log to /var/log/messages.

@version: 3.2
# Based on syslog-ng default configuration file for Gentoo Linux

options { 
    chain_hostnames(no);

    # The default action of syslog-ng is to log a STATS line
    # to the file every 10 minutes.  That's pretty ugly after a while.
    # Change it to every 12 hours so you get a nice daily update of
    # how many messages syslog-ng missed (0).
    stats_freq(43200); 
};

source systemSource {
    unix-stream("/dev/log" max-connections(256));
    internal();
    file("/proc/kmsg");
};

template colouredTemplate {
    template("$LEVEL_NUM $S_DATE $MSGHDR$MSG\n");
};

destination consoleDestination {
    program("/usr/local/bin/logcolourer >/dev/tty12"
        template(colouredTemplate));
};
destination colouredDestination {
    program("/usr/local/bin/logcolourer >>/var/log/coloured"
        template(colouredTemplate));
};
destination messageDestination {
    file("/var/log/messages");
};

filter infoFilter { "$LEVEL_NUM" < "7" };
filter noticeFilter { "$LEVEL_NUM" < "6" };

log {
    source(systemSource);
    filter(noticeFilter);
    destination(consoleDestination);
};
log {
    source(systemSource);
    filter(infoFilter);
    destination(colouredDestination);
};
log {
    source(systemSource);
    destination(messageDestination);
};

[Customizing]


Related

Wiki: Customizing
Wiki: Home