diff options
author | David Robillard <d@drobilla.net> | 2010-01-06 23:48:32 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-01-06 23:48:32 +0000 |
commit | fd945013143466e26f0d481d675401fa745716ba (patch) | |
tree | d029aef1cb9f87a061c04833b3597f8f8f40b90a /src/log.cpp | |
parent | c507f80c17ef71e9d096c8c4bdd729c7adc68f6e (diff) | |
download | raul-fd945013143466e26f0d481d675401fa745716ba.tar.gz raul-fd945013143466e26f0d481d675401fa745716ba.tar.bz2 raul-fd945013143466e26f0d481d675401fa745716ba.zip |
Fancy (optinally) coloured logging system.
Do all logging output via Raul logging streams.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2348 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/log.cpp')
-rw-r--r-- | src/log.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..e9a61b2 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,85 @@ +/* This file is part of Raul. + * Copyright (C) 2009 Dave Robillard <http://drobilla.net> + * + * Raul is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Raul is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "raul/log.hpp" +#include "raul-config.h" + +namespace Raul { + +#ifdef LOG_COLOUR + +LogBuffer info_buffer("", LogBuffer::GREEN); +LogBuffer warn_buffer("", LogBuffer::YELLOW); +LogBuffer error_buffer("", LogBuffer::RED); +#ifdef LOG_DEBUG +LogBuffer debug_buffer("", LogBuffer::CYAN); +#else +NullBuffer debug_buffer; +#endif + +#else // !LOG_COLOUR + +LogBuffer info_buffer("INFO: "); +LogBuffer warn_buffer("WARNING: "); +LogBuffer error_buffer("ERROR: "); +#ifdef LOG_DEBUG +LogBuffer debug_buffer("DEBUG: "); +#else +NullBuffer debug_buffer; +#endif + +#endif // LOG_COLOUR + +std::ostream info(&info_buffer); +std::ostream warn(&warn_buffer); +std::ostream error(&error_buffer); +std::ostream debug(&debug_buffer); + + +const char* +Raul::LogBuffer::colour(Colour c) +{ + std::stringstream ss; + ss << "\033[0;" << _colour << "m"; + return ss.str().c_str(); +} + + +const char* +Raul::LogBuffer::plain() +{ + return "\033[0m"; +} + + +void +Raul::LogBuffer::emit() +{ + if (_colour != DEFAULT) + _out << colour(_colour); + + _out << _prefix << _line; + + if (_colour != DEFAULT) + _out << plain(); + + _out << std::endl; + _line.clear(); +} + + +} // namespace Raul |