[asterisk-scf-commits] asterisk-scf/integration/logger.git branch "logformat" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Apr 21 06:18:23 CDT 2011


branch "logformat" has been updated
       via  ec3ff2a4feb2e6f0ed4d7438f20bbbce9f41fd4b (commit)
      from  9931234067dd4a94807fed969afdffdc968b2c98 (commit)

Summary of changes:
 client/src/LogFormatter.cpp               |   28 +++++++++++++++++-----------
 include/AsteriskSCF/Logger/LogConsts.h    |    4 ++++
 include/AsteriskSCF/Logger/LogFormatter.h |   24 ++++++++++++++++++++++++
 include/AsteriskSCF/logger.h              |   22 +++-------------------
 4 files changed, 48 insertions(+), 30 deletions(-)


- Log -----------------------------------------------------------------
commit ec3ff2a4feb2e6f0ed4d7438f20bbbce9f41fd4b
Author: Fred Anderson <fanderson at digium.com>
Date:   Thu Apr 21 06:16:38 2011 -0500

    Cleaned up comments; added $g option to format str

diff --git a/client/src/LogFormatter.cpp b/client/src/LogFormatter.cpp
index a1082f3..7128b0f 100644
--- a/client/src/LogFormatter.cpp
+++ b/client/src/LogFormatter.cpp
@@ -65,22 +65,22 @@ void LogFormatter::logs(const std::string& name, Level level, const std::string&
     std::string outStr = getFormat();
     std::size_t pos;
 
-    // Logger name
     if ((pos=outStr.find(SPECIFIER("n"),0))!=std::string::npos)
     {
+        // Logger name
         outStr.replace(pos,2,name);
     }
-    // Priority / level
     if ((pos=outStr.find(SPECIFIER("p"),0))!=std::string::npos)
     {
+        // Priority / level
         std::stringstream s("");
 
         s << level;
         outStr.replace(pos,2,s.str());
     }
-    // Client host name
     if ((pos=outStr.find(SPECIFIER("h"),0))!=std::string::npos)
     {
+        // Client host name
         char host[HOSTNAME_SIZE];
 
         if (gethostname(host,HOSTNAME_SIZE))
@@ -89,9 +89,9 @@ void LogFormatter::logs(const std::string& name, Level level, const std::string&
         }
         outStr.replace(pos,2,std::string(host));
     }
-    // Client timestamp (formatted)
     if ((pos=outStr.find(SPECIFIER("t{"),0))!=std::string::npos)
     {
+        // Client timestamp (formatted)
         try
         {
             std::size_t pos2 = outStr.find("}",pos+3);
@@ -107,33 +107,39 @@ void LogFormatter::logs(const std::string& name, Level level, const std::string&
         }
         catch (...)
         {
-           // Don't do anything to outStr, so timestamp will look bad
-           // and signal to someone that the format is wrong
+           // Don't do anything to outStr, so the timestamp format specifier will show up
+           // in the output and signal to someone that the format is wrong
         }
     }
-    // Client timestamp (unformatted)
+    else
     if ((pos=outStr.find(SPECIFIER("t"),0))!=std::string::npos)
     {
+        // Client timestamp (unformatted)
         char timeStamp[TIMESTAMP_SIZE];
         std::time_t now = time(NULL);
      
         strftime(timeStamp,TIMESTAMP_SIZE,TimestampFormat.c_str(),localtime(&now));
         outStr.replace(pos,2,std::string(timeStamp));
     }
-    // Thread ID
     if ((pos=outStr.find(SPECIFIER("i"),0))!=std::string::npos)
     {
+        // Thread ID
         std::stringstream s("");
 
         s << boost::this_thread::get_id();
         outStr.replace(pos,2,s.str());
     }
-    // Time delta since last message
+    if ((pos=outStr.find(SPECIFIER("g"),0))!=std::string::npos)
+    {
+        // Process ID
+        outStr.replace(pos,2,boost::lexical_cast<std::string>(getpid()));
+    }
     if ((pos=outStr.find(SPECIFIER("d"),0))!=std::string::npos)
     {
-        // take labs() on the off chance delta represents a negative duration
+        // Time delta since last message
         boost::posix_time::time_duration delta = 
                 boost::posix_time::microsec_clock::universal_time() - mLastMsgTime;
+        // take labs() on the off chance delta represents a negative duration
         long secs = labs(delta.total_milliseconds() / 1000),
              msecs = labs(delta.total_milliseconds() % 1000);
         std::stringstream s("");
@@ -141,9 +147,9 @@ void LogFormatter::logs(const std::string& name, Level level, const std::string&
         s << secs << "." << std::setfill('0') << std::setw(3) << msecs;
         outStr.replace(pos,2,s.str());
     }
-    // Check for message last so we don't modify it
     if ((pos=outStr.find(SPECIFIER("m"),0))!=std::string::npos)
     {
+        // Check for message specifier last so we don't modify the message itself
         outStr.replace(pos,2,message);
     }
     mOut->logs(name,level,outStr);
diff --git a/include/AsteriskSCF/Logger/LogConsts.h b/include/AsteriskSCF/Logger/LogConsts.h
index e82152d..3a57b51 100644
--- a/include/AsteriskSCF/Logger/LogConsts.h
+++ b/include/AsteriskSCF/Logger/LogConsts.h
@@ -25,6 +25,10 @@ namespace System
 namespace Logging
 {
 
+/**
+ * Constants used in the logger client
+ */
+
 const int MESSAGE_SIZE = 512;
 
 const int TIMESTAMP_SIZE = 64;
diff --git a/include/AsteriskSCF/Logger/LogFormatter.h b/include/AsteriskSCF/Logger/LogFormatter.h
index ab6754b..dd76f8f 100644
--- a/include/AsteriskSCF/Logger/LogFormatter.h
+++ b/include/AsteriskSCF/Logger/LogFormatter.h
@@ -55,6 +55,28 @@ namespace System
 namespace Logging
 {
 
+/**
+ * Class used to format log messages before sending them to a LogOut. The LogFormatter
+ * uses a format string to describe what a formatted log message should look like.
+ *
+ * The format string is composed of format specifiers and other text, much like
+ * the printf statement. Valid format specifiers are (the $ is really whatever is
+ * defined by the SPECIFIER macro) :
+ * 
+ * $n - the name of the logger
+ * $p - the priority/level of the message being logged
+ * $h - the client host name
+ * $t - current time, can be further formatted with additional specifiers following the 
+ *      strftime() format. The additional specifiers should be in a set of curly braces, 
+ *      like: $t{%x %X} would format the time into a date/time string. If no additional
+ *      format specifiers are given (ie, just $t), the system uses whatever the 
+ *      TimestampFormat const is set to.
+ * $i - current thread id
+ * $g - current process id
+ * $d - delta in time between this message and the last one (shows as seconds.milliseconds)
+ * $m - the message to log. You probably always want this one.
+ */
+
 class LogFormatter
 {
 public:
@@ -75,6 +97,8 @@ private:
 /**
  * Returns a semi-formatted string containing some source code
  * information (line, function, file)
+ *
+ * See description of SRCINFO macro for formatting options.
  */
 ASTERISK_SCF_ICEBOX_EXPORT std::string sourceInfoStr(const std::string& fmt, unsigned int line, 
                                                      const char* fcn, const char* file);
diff --git a/include/AsteriskSCF/logger.h b/include/AsteriskSCF/logger.h
index ac218bb..80fb515 100644
--- a/include/AsteriskSCF/logger.h
+++ b/include/AsteriskSCF/logger.h
@@ -166,7 +166,6 @@ public:
      */
     Logger(const std::string& name, LogOut& out, Level logLevel = Debug,
            const std::string& fmtStr = DefaultLogFormat);
-
     /**
      * If true, this Logger would log messages of the given Level.
      *
@@ -174,7 +173,6 @@ public:
      * @return true if enabled for given level.
      */
     bool isEnabledFor(Level level) const;
-
     /**
      * Ostream style logging.
      *
@@ -182,12 +180,10 @@ public:
      * @return LogStream that logs at the given level.
      */
     CondStream operator()(Level level) const;
-
     /**
      * Log a single message.
      */
     void logs(Level level, const std::string& message);
-
     /**
      * Log a single printf-formatted message.
      */
@@ -195,7 +191,6 @@ public:
     __attribute__((format(printf, 3, 4)))
 #endif
     void logf(Level level, char const *fmt, ...);
-
     /**
      * Log a single vprintf-formatted message.
      */
@@ -203,33 +198,24 @@ public:
     __attribute__((format(printf, 3, 0)))
 #endif
     void vlogf(Level level, char const *fmt, va_list ap);
-
     Logger getChild(const std::string& childName);
-
     std::vector<Logger> getChildren() const;
-
     const std::string& getName() const;
-
     LogOut& getOutput() const;
-
     void setOutput(LogOut& out);
-
     /**
      * Sets the current logLevel.  Until unsetLevel() is called, we are no
      * longer affected by changes to our parent's log level.
      */
     void setLevel(Level logLevel);
-
     /**
      * Changes our logLevel to now inherit from our parent.
      */
     void unsetLevel();
-
     /**
      * Returns the effective level of this Logger.
      */
     Level getEffectiveLevel() const;
-
     /**
      * Sets the current format string for log messages for this logger.
      * The format string is composed of format specifiers and other text, much like
@@ -242,22 +228,20 @@ public:
      * $t - current time, can be further formatted with additional specifiers following the strftime() format. The 
      *      additional specifiers should be in a set of curly braces, like: $t{%x %X} would format the time into a date/time string.
      *      If no additional format specifiers are given (ie, just $t), the system uses whatever the TimestampFormat const is set to.
-     * $i - thread id
+     * $i - current thread id
+     * $g - current process id
      * $d - delta in time between this message and the last one (shows as seconds.milliseconds)
      * $m - the message to log. You probably always want this one.
      */
     void setFormat(const std::string& fmtStr);
-
     /**
-     * Reverts logger's formatter to whatever its parent's is
+     * Forces logger to use its parent's formatter
      */
     void unsetFormat();
-
     /**
      * Returns the effective formatter of this logger
      */
     boost::shared_ptr<LogFormatter> getEffectiveFormatter() const;
-
 private:
     boost::shared_ptr<LoggerImpl> mImpl;
 };

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/logger.git



More information about the asterisk-scf-commits mailing list