Skip to content

Commit

Permalink
REMOVED unwanted linebreaks from Python logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ksterker committed Mar 17, 2013
1 parent 8f89c9a commit 73eff5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/base/logging.cc
Expand Up @@ -33,7 +33,15 @@ namespace base
{
void stderr_to_log::write (const char *msg)
{
LOG(ERROR) << msg;
if (strchr(msg, '\n') == NULL)
{
Buffer << msg;
}
else
{
LOG(ERROR) << Buffer.str() << msg;
Buffer.str("");
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/base/logging.h
Expand Up @@ -28,21 +28,26 @@
#ifndef LOGGING_H_
#define LOGGING_H_

#include <sstream>

namespace base
{
/*
/**
* Redirect Python stderr to our own logging
* implementation. For this to work, an instance
* of this class has to be assigned to sys.stderr.
*/
class stderr_to_log
{
public:
/*
/**
* Redirect message to log, using level ERROR.
* @param msg the message to append to the log.
*/
void write (const char *msg);
private:
/// buffer log output until we get a linebreak
std::ostringstream Buffer;
};
}

Expand Down

0 comments on commit 73eff5d

Please sign in to comment.