class Poco::ColorConsoleChannel

Overview

A channel that writes to an ostream. More…

#include <ConsoleChannel.h>

class ColorConsoleChannel: public Poco::Channel
{
public:
    // construction

    ColorConsoleChannel();
    ColorConsoleChannel(std::ostream& str);

    // methods

    virtual
    void
    log(const Message& msg);

    virtual
    void
    setProperty(
        const std::string& name,
        const std::string& value
        );

    virtual
    std::string
    getProperty(const std::string& name) const;

protected:
    // enums

    enum Color;

    // methods

    Color
    parseColor(const std::string& color) const;

    std::string
    formatColor(Color color) const;

    void
    initColors();
};

Inherited Members

public:
    // methods

    virtual
    void
    setProperty(
        const std::string& name,
        const std::string& value
        ) = 0;

    virtual
    std::string
    getProperty(const std::string& name) const = 0;

    void
    duplicate() const;

    void
    release() const;

    int
    referenceCount() const;

    virtual
    void
    open();

    virtual
    void
    close();

    virtual
    void
    log(const Message& msg) = 0;

    virtual
    void
    setProperty(
        const std::string& name,
        const std::string& value
        );

    virtual
    std::string
    getProperty(const std::string& name) const;

Detailed Documentation

A channel that writes to an ostream.

Only the message’s text is written, followed by a newline.

Messages can be colored depending on priority. The console device must support ANSI escape codes in order to display colored messages.

To enable message coloring, set the “enableColors” property to true (default). Furthermore, colors can be configured by setting the following properties (default values are given in parenthesis):

* traceColor (gray)
* debugColor (gray)
* informationColor (default)
* noticeColor (default)
* warningColor (yellow)
* errorColor (lightRed)
* criticalColor (lightRed)
* fatalColor (lightRed)

The following color values are supported:

* default
* black
* red
* green
* brown
* blue
* magenta
* cyan
* gray
* darkgray
* lightRed
* lightGreen
* yellow
* lightBlue
* lightMagenta
* lightCyan
* white

Chain this channel to a FormattingChannel with an appropriate Formatter to control what is contained in the text.

Similar to StreamChannel, except that a static mutex is used to protect against multiple console channels concurrently writing to the same stream.

Construction

ColorConsoleChannel()

Creates the channel and attaches std::clog.

ColorConsoleChannel(std::ostream& str)

Creates the channel using the given stream.

Methods

virtual
void
log(const Message& msg)

Logs the given message to the channel’s stream.

virtual
void
setProperty(
    const std::string& name,
    const std::string& value
    )

Sets the property with the given name.

The following properties are supported:

* enableColors:      Enable or disable colors.
* traceColor:        Specify color for trace messages.
* debugColor:        Specify color for debug messages.
* informationColor:  Specify color for information messages.
* noticeColor:       Specify color for notice messages.
* warningColor:      Specify color for warning messages.
* errorColor:        Specify color for error messages.
* criticalColor:     Specify color for critical messages.
* fatalColor:        Specify color for fatal messages.

See the class documentation for a list of supported color values.

virtual
std::string
getProperty(const std::string& name) const

Returns the value of the property with the given name.

See setProperty() for a description of the supported properties.