Sha256: 41ad84e8b1bb1472dd12814d6ed23d03626cf89f5876582b0727b819906bfc41

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

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

using namespace std;

namespace leatherman { namespace logging {

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

        static const string cyan = "\33[0;36m";
        static const string green = "\33[0;32m";
        static const string yellow = "\33[0;33m";
        static const string red = "\33[0;31m";
        static const string reset = "\33[0m";

        if (level == log_level::trace || level == log_level::debug) {
            dst << cyan;
        } else if (level == log_level::info) {
            dst << green;
        } else if (level == log_level::warning) {
            dst << yellow;
        } else if (level == log_level::error || level == log_level::fatal) {
            dst << red;
        } else {
            dst << reset;
        }
    }

    bool color_supported(ostream& dst)
    {
        return (&dst == &cout && isatty(fileno(stdout))) || (&dst == &cerr && isatty(fileno(stderr)));
    }

}}  // 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/posix/logging.cc
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/logging/src/posix/logging.cc
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/logging/src/posix/logging.cc
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/logging/src/posix/logging.cc