Sha256: 6b81df038628d711a3fe7f1fd0f2300c627e28e47595d4a7720a4119d1ea26ff

Contents?: true

Size: 1.83 KB

Versions: 16

Compression:

Stored size: 1.83 KB

Contents

#include <leatherman/logging/logging.hpp>
#include <boost/nowide/iostream.hpp>
#include <windows.h>

using namespace std;

namespace leatherman { namespace logging {
    static HANDLE stdHandle;
    static WORD originalAttributes;

    void colorize(ostream& dst, log_level level)
    {
        if (!get_colorization()) {
            return;
        }

        // The ostream may have buffered data, and changing the console color will affect any buffered data written
        // later. Ensure the buffer is flushed before changing the console color.
        dst.flush();
        if (level == log_level::trace || level == log_level::debug) {
            SetConsoleTextAttribute(stdHandle, FOREGROUND_BLUE | FOREGROUND_GREEN);
        } else if (level == log_level::info) {
            SetConsoleTextAttribute(stdHandle, FOREGROUND_GREEN);
        } else if (level == log_level::warning) {
            SetConsoleTextAttribute(stdHandle, FOREGROUND_RED | FOREGROUND_GREEN);
        } else if (level == log_level::error || level == log_level::fatal) {
            SetConsoleTextAttribute(stdHandle, FOREGROUND_RED);
        } else {
            SetConsoleTextAttribute(stdHandle, originalAttributes);
        }
    }

    bool color_supported(ostream& dst)
    {
        bool colorize = false;
        if (&dst == &cout || &dst == &boost::nowide::cout) {
            stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
            colorize = true;
        } else if (&dst == &cerr || &dst == &boost::nowide::cerr) {
            stdHandle = GetStdHandle(STD_ERROR_HANDLE);
            colorize = true;
        }

        if (colorize) {
            CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
            GetConsoleScreenBufferInfo(stdHandle, &csbiInfo);
            originalAttributes = csbiInfo.wAttributes;
        }
        return colorize;
    }

}}  // namespace leatherman::logging

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/logging/src/windows/logging.cc
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/logging/src/windows/logging.cc
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/logging/src/windows/logging.cc