summaryrefslogtreecommitdiffstats
path: root/raul
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-01-06 23:48:32 +0000
committerDavid Robillard <d@drobilla.net>2010-01-06 23:48:32 +0000
commitfd945013143466e26f0d481d675401fa745716ba (patch)
treed029aef1cb9f87a061c04833b3597f8f8f40b90a /raul
parentc507f80c17ef71e9d096c8c4bdd729c7adc68f6e (diff)
downloadraul-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 'raul')
-rw-r--r--raul/Atom.hpp14
-rw-r--r--raul/AtomLiblo.hpp3
-rw-r--r--raul/AtomRDF.hpp4
-rw-r--r--raul/Process.hpp3
-rw-r--r--raul/RingBuffer.hpp3
-rw-r--r--raul/TableImpl.hpp6
-rw-r--r--raul/log.hpp94
7 files changed, 116 insertions, 11 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
index 7581e46..4dfb723 100644
--- a/raul/Atom.hpp
+++ b/raul/Atom.hpp
@@ -210,4 +210,18 @@ static inline std::ostream& operator<<(std::ostream& os, const Raul::Atom& atom)
return os;
}
+static inline std::ostream& operator<<(std::ostream& os, Raul::Atom::Type type)
+{
+ switch (type) {
+ case Raul::Atom::NIL: return os << "Nil";
+ case Raul::Atom::INT: return os << "Int32";
+ case Raul::Atom::FLOAT: return os << "Float";
+ case Raul::Atom::BOOL: return os << "Bool";
+ case Raul::Atom::URI: return os << "URI";
+ case Raul::Atom::STRING: return os << "String";
+ case Raul::Atom::BLOB: return os << "Blob";
+ }
+ return os;
+}
+
#endif // RAUL_ATOM_HPP
diff --git a/raul/AtomLiblo.hpp b/raul/AtomLiblo.hpp
index 7494ae4..fe6888a 100644
--- a/raul/AtomLiblo.hpp
+++ b/raul/AtomLiblo.hpp
@@ -20,6 +20,7 @@
#include <iostream>
#include <lo/lo.h>
+#include "raul/log.hpp"
#include "raul/Atom.hpp"
namespace Raul {
@@ -85,7 +86,7 @@ lo_arg_to_atom(char type, lo_arg* arg)
case 'F':
return Atom((bool)false);
default:
- std::cerr << "WARNING: Unable to convert OSC type '"
+ warn << "Unable to convert OSC type '"
<< type << "' to Atom" << std::endl;
return Atom();
}
diff --git a/raul/AtomRDF.hpp b/raul/AtomRDF.hpp
index 3c3373d..0b961d2 100644
--- a/raul/AtomRDF.hpp
+++ b/raul/AtomRDF.hpp
@@ -22,7 +22,7 @@
#include <string>
#include <sstream>
#include <cmath>
-
+#include "raul/log.hpp"
#include "raul/Atom.hpp"
#include "redlandmm/Node.hpp"
#include "redlandmm/World.hpp"
@@ -101,7 +101,7 @@ atom_to_node(Redland::World& world, const Atom& atom)
case Atom::BLOB:
case Atom::NIL:
default:
- //std::cerr << "WARNING: Unserializable Atom!" << std::endl;
+ warn << "Unserializable Atom" << std::endl;
break;
}
diff --git a/raul/Process.hpp b/raul/Process.hpp
index 675f1d7..719a9d4 100644
--- a/raul/Process.hpp
+++ b/raul/Process.hpp
@@ -24,6 +24,7 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <boost/utility.hpp>
+#include "raul/log.hpp"
namespace Raul {
@@ -47,7 +48,7 @@ public:
const std::string arguments = command.substr((command.find(" ") + 1));
- std::cerr << "Launching child process '" << executable << "' with arguments '"
+ info << "Launching child process '" << executable << "' with arguments '"
<< arguments << "'" << std::endl;
// Use the same double fork() trick as JACK to prevent zombie children
diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp
index 2c937cf..23d4d90 100644
--- a/raul/RingBuffer.hpp
+++ b/raul/RingBuffer.hpp
@@ -22,6 +22,7 @@
#include <cstring>
#include <iostream>
#include <glib.h>
+#include "raul/log.hpp"
namespace Raul {
@@ -189,7 +190,7 @@ bool
RingBuffer<T>::skip(size_t size)
{
if (read_space() < size) {
- std::cerr << "WARNING: Attempt to skip past end of MIDI ring buffer" << std::endl;
+ warn << "Attempt to skip past end of MIDI ring buffer" << std::endl;
return false;
}
diff --git a/raul/TableImpl.hpp b/raul/TableImpl.hpp
index 81971d6..0b32a29 100644
--- a/raul/TableImpl.hpp
+++ b/raul/TableImpl.hpp
@@ -241,12 +241,6 @@ Table<K, T>::cram(const Table<K,T>& range)
_entries = new_entries;
- /*std::cerr << "********************************\n";
- for (size_t i=0; i < size(); ++i) {
- std::cerr << _entries[i].first << std::endl;
- }
- std::cerr << "********************************\n";*/
-
assert(size() == orig_size + range.size());
#ifdef TABLE_SORT_DEBUG
assert(is_sorted());
diff --git a/raul/log.hpp b/raul/log.hpp
new file mode 100644
index 0000000..17d728f
--- /dev/null
+++ b/raul/log.hpp
@@ -0,0 +1,94 @@
+/* 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
+ */
+
+#ifndef RAUL_LOG_HPP
+#define RAUL_LOG_HPP
+
+#include <iostream>
+#include <sstream>
+
+namespace Raul {
+
+class LogBuffer : public std::streambuf
+{
+public:
+ enum Colour {
+ DEFAULT = 0,
+ RED = 31,
+ GREEN,
+ YELLOW,
+ BLUE,
+ MAGENTA,
+ CYAN,
+ WHITE
+ };
+
+ LogBuffer(const char* prefix="", Colour colour=DEFAULT)
+ : _prefix(prefix)
+ , _colour(colour)
+ , _out(std::cout)
+ {}
+
+ /** Change the colour of the output, e.g. out << colour(RED) << "red" << endl; */
+ const char* colour(Colour c);
+
+ /** Reset the colour of the output, e.g. out << plain() << "plain" << endl; */
+ const char* plain();
+
+protected:
+ int_type overflow(int_type c) {
+ if (c == '\n')
+ emit();
+ else if (c != traits_type::eof())
+ _line += c;
+
+ return c;
+ }
+
+ int sync() {
+ if (!_line.empty())
+ emit();
+ return 0;
+ }
+
+private:
+ void emit();
+
+ const char* _prefix;
+ Colour _colour;
+ std::string _line;
+ std::ostream& _out;
+};
+
+
+class NullBuffer : public std::streambuf
+{
+protected:
+ int_type overflow(int_type c) { return c; }
+ int sync() { return 0; }
+};
+
+
+extern std::ostream info;
+extern std::ostream warn;
+extern std::ostream error;
+extern std::ostream debug;
+
+
+} // namespace Raul
+
+#endif // RAUL_LOG_HPP