[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
Wed Apr 20 09:12:17 CDT 2011
branch "logformat" has been updated
via 9931234067dd4a94807fed969afdffdc968b2c98 (commit)
from 4abb4342686cdc8df849a76149d0f3baf04fee09 (commit)
Summary of changes:
client/src/LogFormatter.cpp | 18 ++++++++++++++----
client/src/OstreamLogger.cpp | 2 ++
include/AsteriskSCF/Logger/LogFormatter.h | 3 ++-
include/AsteriskSCF/Logger/LogOut.h | 2 ++
4 files changed, 20 insertions(+), 5 deletions(-)
- Log -----------------------------------------------------------------
commit 9931234067dd4a94807fed969afdffdc968b2c98
Author: Fred Anderson <fanderson at digium.com>
Date: Wed Apr 20 09:10:29 2011 -0500
Added protection to formatter and OstreamLogger
diff --git a/client/src/LogFormatter.cpp b/client/src/LogFormatter.cpp
index 42d2dd3..a1082f3 100644
--- a/client/src/LogFormatter.cpp
+++ b/client/src/LogFormatter.cpp
@@ -37,12 +37,22 @@ LogFormatter::~LogFormatter()
void LogFormatter::setFormat(const std::string& fmtStr)
{
+ boost::unique_lock<boost::shared_mutex> lock(mMutex);
mFormat = fmtStr;
}
+std::string LogFormatter::getFormat()
+{
+ boost::shared_lock<boost::shared_mutex> lock(mMutex);
+
+ return mFormat;
+}
+
+
void LogFormatter::setOutput(LogOut* out)
{
+ boost::unique_lock<boost::shared_mutex> lock(mMutex);
mOut = out;
}
@@ -52,7 +62,7 @@ void LogFormatter::setOutput(LogOut* out)
*/
void LogFormatter::logs(const std::string& name, Level level, const std::string& message)
{
- std::string outStr(mFormat);
+ std::string outStr = getFormat();
std::size_t pos;
// Logger name
@@ -71,11 +81,11 @@ void LogFormatter::logs(const std::string& name, Level level, const std::string&
// Client host name
if ((pos=outStr.find(SPECIFIER("h"),0))!=std::string::npos)
{
- char host[128];
+ char host[HOSTNAME_SIZE];
- if (gethostname(host,128))
+ if (gethostname(host,HOSTNAME_SIZE))
{
- std::strncpy(host,"unknown_host",128);
+ std::strncpy(host,"unknown_host",HOSTNAME_SIZE);
}
outStr.replace(pos,2,std::string(host));
}
diff --git a/client/src/OstreamLogger.cpp b/client/src/OstreamLogger.cpp
index 0233e72..4e7cb19 100644
--- a/client/src/OstreamLogger.cpp
+++ b/client/src/OstreamLogger.cpp
@@ -33,11 +33,13 @@ public:
void logs(const std::string& name, Level logLevel,
const std::string& message)
{
+ boost::unique_lock<boost::mutex> lock(mMutex);
mOut << message << '\n';
}
private:
std::ostream& mOut;
+ boost::mutex mMutex;
};
}
diff --git a/include/AsteriskSCF/Logger/LogFormatter.h b/include/AsteriskSCF/Logger/LogFormatter.h
index 63a0dbe..ab6754b 100644
--- a/include/AsteriskSCF/Logger/LogFormatter.h
+++ b/include/AsteriskSCF/Logger/LogFormatter.h
@@ -68,7 +68,8 @@ private:
LogOut* mOut;
std::string mFormat;
boost::posix_time::ptime mLastMsgTime;
- boost::posix_time::time_duration timeDelta();
+ boost::shared_mutex mMutex;
+ std::string getFormat();
};
/**
diff --git a/include/AsteriskSCF/Logger/LogOut.h b/include/AsteriskSCF/Logger/LogOut.h
index 482612f..56efca5 100644
--- a/include/AsteriskSCF/Logger/LogOut.h
+++ b/include/AsteriskSCF/Logger/LogOut.h
@@ -29,6 +29,8 @@ namespace Logging
/**
* Interface abstracting how the logs actually get written.
+ *
+ * NOTE: it is your responsibility to make sure your LogOut implementation is threadsafe
*/
class LogOut
{
-----------------------------------------------------------------------
--
asterisk-scf/integration/logger.git
More information about the asterisk-scf-commits
mailing list