summaryrefslogtreecommitdiff
path: root/i
diff options
context:
space:
mode:
Diffstat (limited to 'i')
-rw-r--r--i/marvin/src/Makefile.defs6
-rw-r--r--i/marvin/src/log/log.cc23
-rw-r--r--i/marvin/src/log/log.hh9
-rw-r--r--i/marvin/src/log/log_message.cc28
-rw-r--r--i/marvin/src/log/log_message.hh4
-rw-r--r--i/marvin/src/log/test_log.cc2
6 files changed, 51 insertions, 21 deletions
diff --git a/i/marvin/src/Makefile.defs b/i/marvin/src/Makefile.defs
index 8b0e709..2f226d3 100644
--- a/i/marvin/src/Makefile.defs
+++ b/i/marvin/src/Makefile.defs
@@ -22,7 +22,11 @@ CXXFLAGS += -fmessage-length=0
# Attention, il y a un problème de dépendences dans l'ordre des SUBDIRS à
# cause de la génération des règles.
-SUBDIRS =
+SUBDIRS = utils utils/meta \
+ log serial timer \
+ config data scheduler \
+ proto asserv\
+ motor
LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
LEX = flex
diff --git a/i/marvin/src/log/log.cc b/i/marvin/src/log/log.cc
index 1818b99..e1799b0 100644
--- a/i/marvin/src/log/log.cc
+++ b/i/marvin/src/log/log.cc
@@ -25,14 +25,8 @@
#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)
+Log::Log (const char *module, const char *instance, Level level)
+ : module_ (module), instance_ (instance), level_(level)
{
}
@@ -100,3 +94,16 @@ Log::toLevelMask (Log::Level level)
return static_cast <Level> ((level - 1) | level);
}
+/// Récupère le niveau de log
+Log::Level
+Log::getLevel(void) const
+{
+ return level_;
+}
+
+/// Set le niveau de log
+void
+Log::setLevel(Level level)
+{
+ level_ = level;
+}
diff --git a/i/marvin/src/log/log.hh b/i/marvin/src/log/log.hh
index 387a2c4..4dbaf16 100644
--- a/i/marvin/src/log/log.hh
+++ b/i/marvin/src/log/log.hh
@@ -46,11 +46,10 @@ class Log
private:
const char *module_;
const char *instance_;
+ Level level_;
public:
/// Constructeur.
- Log (const char *module);
- /// Constructeur.
- Log (const char *module, const char *instance);
+ Log (const char *module, const char *instance = 0, Level level = info);
/// Crée un nouveau LogMessage.
LogMessage operator() (const char *msg, Level level = info) const;
/// Récupère le module.
@@ -63,6 +62,10 @@ class Log
static Level toLevel (const std::string &level);
/// Change un niveau de log en masque.
static Level toLevelMask (Level level);
+ /// Récupère le niveau de log
+ Level getLevel(void) const;
+ /// Set le niveau de log
+ void setLevel(Level level);
};
#include "log_message.hh"
diff --git a/i/marvin/src/log/log_message.cc b/i/marvin/src/log/log_message.cc
index 4a3af9a..054ef78 100644
--- a/i/marvin/src/log/log_message.cc
+++ b/i/marvin/src/log/log_message.cc
@@ -29,23 +29,30 @@
/// 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;
+ writeAllowed_ = level <= log.getLevel();
+
+ if(writeAllowed_)
+ {
+ std::cout << log.getModule () << ':';
+ if (log.getInstance ())
+ std::cout << ' ' << log.getInstance () << ':';
+ std::cout << ' ' << msg;
+ }
}
/// Destructeur.
LogMessage::~LogMessage (void)
{
- std::cout << std::endl;
+ if(writeAllowed_)
+ std::cout << std::endl;
}
/// Output a string or a variable name.
LogMessage &
LogMessage::operator<< (const char *s)
{
- std::cout << ' ' << s;
+ if(writeAllowed_)
+ std::cout << ' ' << s;
return *this;
}
@@ -53,7 +60,8 @@ LogMessage::operator<< (const char *s)
LogMessage &
LogMessage::operator<< (const std::string &s)
{
- std::cout << ' ' << s;
+ if(writeAllowed_)
+ std::cout << ' ' << s;
return *this;
}
@@ -61,7 +69,8 @@ LogMessage::operator<< (const std::string &s)
LogMessage &
LogMessage::operator<< (int i)
{
- std::cout << ' ' << i;
+ if(writeAllowed_)
+ std::cout << ' ' << i;
return *this;
}
@@ -69,7 +78,8 @@ LogMessage::operator<< (int i)
LogMessage &
LogMessage::operator<< (double d)
{
- std::cout << ' ' << d;
+ if(writeAllowed_)
+ std::cout << ' ' << d;
return *this;
}
diff --git a/i/marvin/src/log/log_message.hh b/i/marvin/src/log/log_message.hh
index e5a9e20..1786551 100644
--- a/i/marvin/src/log/log_message.hh
+++ b/i/marvin/src/log/log_message.hh
@@ -29,6 +29,10 @@
class LogMessage
{
+ private:
+ /// Niveau de log suffisant?
+ bool writeAllowed_;
+
public:
/// Constructeur.
LogMessage (const Log &log, const char *msg, Log::Level level);
diff --git a/i/marvin/src/log/test_log.cc b/i/marvin/src/log/test_log.cc
index 0cd7d42..3be9b68 100644
--- a/i/marvin/src/log/test_log.cc
+++ b/i/marvin/src/log/test_log.cc
@@ -30,5 +30,7 @@ main (void)
Log log ("main");
log ("foo") << "bar" << 4 << "foobar" << 5.6;
log ("bar", Log::error) << "foo" << 5;
+ log ("bar", Log::info) << "Chier" << 3 << "Info" << 2.3;
+ log ("bar", Log::debug) << "Partout" << 3 << "Debug" << 2.3;
return 0;
}