summaryrefslogtreecommitdiff
path: root/i/marvin/src/log
diff options
context:
space:
mode:
authorhaller2005-11-17 11:10:17 +0000
committerhaller2005-11-17 11:10:17 +0000
commitda4a77ff094a0dc74414ec1de2cac08e8b7b60f4 (patch)
tree402c39246c164af44648fd98d2ea85500d58df58 /i/marvin/src/log
parent164d8870bc058450e6967a594dd9033d088316af (diff)
Importation brut du code récupérable de robert
Diffstat (limited to 'i/marvin/src/log')
-rw-r--r--i/marvin/src/log/Makefile.defs7
-rw-r--r--i/marvin/src/log/log.cc102
-rw-r--r--i/marvin/src/log/log.hh70
-rw-r--r--i/marvin/src/log/log_message.cc75
-rw-r--r--i/marvin/src/log/log_message.hh52
-rw-r--r--i/marvin/src/log/log_message.tcc36
-rw-r--r--i/marvin/src/log/test_log.cc34
7 files changed, 376 insertions, 0 deletions
diff --git a/i/marvin/src/log/Makefile.defs b/i/marvin/src/log/Makefile.defs
new file mode 100644
index 0000000..8462793
--- /dev/null
+++ b/i/marvin/src/log/Makefile.defs
@@ -0,0 +1,7 @@
+PROGRAMS += test_log
+
+log_OBJECTS = log.o log_message.o
+
+test_log_OBJECTS = test_log.o $(log_OBJECTS)
+
+test_log: $(test_log_OBJECTS)
diff --git a/i/marvin/src/log/log.cc b/i/marvin/src/log/log.cc
new file mode 100644
index 0000000..1818b99
--- /dev/null
+++ b/i/marvin/src/log/log.cc
@@ -0,0 +1,102 @@
+// log.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program 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.
+//
+// This program 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 more 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "log.hh"
+
+/// Constructeur.
+Log::Log (const char *module)
+ : module_ (module), instance_ (0)
+{
+}
+
+/// Constructeur.
+Log::Log (const char *module, const char *instance)
+ : module_ (module), instance_ (instance)
+{
+}
+
+/// Crée un nouveau LogMessage.
+LogMessage
+Log::operator() (const char *msg, Level level/*info*/) const
+{
+ return LogMessage (*this, msg, level);
+}
+
+/// Traduit le niveau de log.
+std::string
+Log::toString (Level level)
+{
+ switch (level)
+ {
+ case none:
+ return "none";
+ case fatal:
+ return "fatal";
+ case error:
+ return "error";
+ case warning:
+ return "warning";
+ case info:
+ return "info";
+ case debug:
+ return "debug";
+ case verydebug:
+ return "verydebug";
+ default:
+ return "logunknown";
+ }
+}
+
+/// Traduit le niveau de log.
+Log::Level
+Log::toLevel (const std::string &level)
+{
+ switch (level[0])
+ {
+ case 'n':
+ return none;
+ case 'f':
+ return fatal;
+ case 'e':
+ return error;
+ case 'w':
+ return warning;
+ case 'i':
+ return info;
+ case 'd':
+ return debug;
+ case 'v':
+ return verydebug;
+ default:
+ return levelReserved;
+ }
+}
+
+/// Change un niveau de log en masque.
+Log::Level
+Log::toLevelMask (Log::Level level)
+{
+ return static_cast <Level> ((level - 1) | level);
+}
+
diff --git a/i/marvin/src/log/log.hh b/i/marvin/src/log/log.hh
new file mode 100644
index 0000000..387a2c4
--- /dev/null
+++ b/i/marvin/src/log/log.hh
@@ -0,0 +1,70 @@
+#ifndef log_hh
+#define log_hh
+// log.h
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program 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.
+//
+// This program 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 more 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include <string>
+
+class LogMessage;
+
+/// Classe de log. Permet de construire des LogMessage.
+class Log
+{
+ public:
+ enum Level
+ {
+ none = 0x00,
+ fatal = 0x01,
+ error = 0x02,
+ warning = 0x04,
+ info = 0x08,
+ debug = 0x10,
+ verydebug = 0x20,
+ levelReserved = 0xffff
+ };
+ private:
+ const char *module_;
+ const char *instance_;
+ public:
+ /// Constructeur.
+ Log (const char *module);
+ /// Constructeur.
+ Log (const char *module, const char *instance);
+ /// Crée un nouveau LogMessage.
+ LogMessage operator() (const char *msg, Level level = info) const;
+ /// Récupère le module.
+ const char *getModule (void) const { return module_; }
+ /// Récupère l'instance.
+ const char *getInstance (void) const { return instance_; }
+ /// Traduit le niveau de log.
+ static std::string toString (Level level);
+ /// Traduit le niveau de log.
+ static Level toLevel (const std::string &level);
+ /// Change un niveau de log en masque.
+ static Level toLevelMask (Level level);
+};
+
+#include "log_message.hh"
+
+#endif // log_hh
diff --git a/i/marvin/src/log/log_message.cc b/i/marvin/src/log/log_message.cc
new file mode 100644
index 0000000..4a3af9a
--- /dev/null
+++ b/i/marvin/src/log/log_message.cc
@@ -0,0 +1,75 @@
+// log_message.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program 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.
+//
+// This program 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 more 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "log_message.hh"
+
+#include <iostream>
+
+/// Constructeur.
+LogMessage::LogMessage (const Log &log, const char *msg, Log::Level level)
+{
+ std::cout << log.getModule () << ':';
+ if (log.getInstance ())
+ std::cout << ' ' << log.getInstance () << ':';
+ std::cout << ' ' << msg;
+}
+
+/// Destructeur.
+LogMessage::~LogMessage (void)
+{
+ std::cout << std::endl;
+}
+
+/// Output a string or a variable name.
+LogMessage &
+LogMessage::operator<< (const char *s)
+{
+ std::cout << ' ' << s;
+ return *this;
+}
+
+/// Output a string or a variable name.
+LogMessage &
+LogMessage::operator<< (const std::string &s)
+{
+ std::cout << ' ' << s;
+ return *this;
+}
+
+/// Output a integer.
+LogMessage &
+LogMessage::operator<< (int i)
+{
+ std::cout << ' ' << i;
+ return *this;
+}
+
+/// Output a double.
+LogMessage &
+LogMessage::operator<< (double d)
+{
+ std::cout << ' ' << d;
+ return *this;
+}
+
diff --git a/i/marvin/src/log/log_message.hh b/i/marvin/src/log/log_message.hh
new file mode 100644
index 0000000..e5a9e20
--- /dev/null
+++ b/i/marvin/src/log/log_message.hh
@@ -0,0 +1,52 @@
+#ifndef log_message_hh
+#define log_message_hh
+// log_message.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program 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.
+//
+// This program 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 more 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include "log.hh"
+
+class LogMessage
+{
+ public:
+ /// Constructeur.
+ LogMessage (const Log &log, const char *msg, Log::Level level);
+ /// Destructeur.
+ ~LogMessage (void);
+ /// Output a string or a variable name.
+ LogMessage &operator<< (const char *s);
+ /// Output a string or a variable name.
+ LogMessage &operator<< (const std::string &s);
+ /// Output a integer.
+ LogMessage &operator<< (int i);
+ /// Output a double.
+ LogMessage &operator<< (double d);
+ /// Output a OutputStreamable as a string.
+ template<typename OutputStreamable>
+ LogMessage &operator<< (const OutputStreamable &o);
+};
+
+#include "log_message.tcc"
+
+#endif // log_message_hh
diff --git a/i/marvin/src/log/log_message.tcc b/i/marvin/src/log/log_message.tcc
new file mode 100644
index 0000000..98ac01b
--- /dev/null
+++ b/i/marvin/src/log/log_message.tcc
@@ -0,0 +1,36 @@
+// log_message.tcc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program 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.
+//
+// This program 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 more 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include <iostream>
+
+/// Output a OutputStreamable as a string.
+template<typename OutputStreamable>
+LogMessage &
+LogMessage::operator<< (const OutputStreamable &o)
+{
+ std::cout << ' ' << o;
+ return *this;
+}
+
diff --git a/i/marvin/src/log/test_log.cc b/i/marvin/src/log/test_log.cc
new file mode 100644
index 0000000..0cd7d42
--- /dev/null
+++ b/i/marvin/src/log/test_log.cc
@@ -0,0 +1,34 @@
+// test_log.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program 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.
+//
+// This program 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 more 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "log.hh"
+
+int
+main (void)
+{
+ Log log ("main");
+ log ("foo") << "bar" << 4 << "foobar" << 5.6;
+ log ("bar", Log::error) << "foo" << 5;
+ return 0;
+}