|
|
@@ -25,54 +25,46 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
*/
|
|
|
|
|
|
#include "Log.h"
|
|
|
-#include "LinearAllocator.h"
|
|
|
-#include "StringStream.h"
|
|
|
#include "Device.h"
|
|
|
#include "RPCServer.h"
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
|
|
|
-static char g_buffer[16 * 1024];
|
|
|
-static LinearAllocator g_allocator(g_buffer, 16 * 1024);
|
|
|
-static StringStream g_stream(g_allocator);
|
|
|
-
|
|
|
-LogLevel Log::m_threshold = LL_DEBUG;
|
|
|
+LogSeverity::Enum Log::m_threshold = LogSeverity::DEBUG;
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-LogLevel Log::threshold()
|
|
|
+LogSeverity::Enum Log::threshold()
|
|
|
{
|
|
|
return m_threshold;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void Log::set_threshold(LogLevel threshold)
|
|
|
+void Log::set_threshold(LogSeverity::Enum threshold)
|
|
|
{
|
|
|
m_threshold = threshold;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
-void Log::log_message(LogLevel level, const char* message, ::va_list arg)
|
|
|
+void Log::log_message(LogSeverity::Enum severity, const char* message, ::va_list arg)
|
|
|
{
|
|
|
- if (level > m_threshold)
|
|
|
+ if (severity > m_threshold)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- switch (level)
|
|
|
- {
|
|
|
- case LL_DEBUG: g_stream << "D: "; break;
|
|
|
- case LL_ERROR: g_stream << "E: "; break;
|
|
|
- case LL_WARN: g_stream << "W: "; break;
|
|
|
- case LL_INFO: g_stream << "I: "; break;
|
|
|
- default: break;
|
|
|
- }
|
|
|
-
|
|
|
char buf[1024];
|
|
|
int len = vsnprintf(buf, 1024 - 2, message, arg);
|
|
|
buf[len] = '\n';
|
|
|
buf[len + 1] = '\0';
|
|
|
- g_stream << buf;
|
|
|
+
|
|
|
+ os::printf(buf);
|
|
|
+ ::fflush(stdout);
|
|
|
+
|
|
|
+ if (device()->rpc() != NULL && string::strlen(buf) > 0)
|
|
|
+ {
|
|
|
+ device()->rpc()->log_to_all(buf, severity);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@@ -80,7 +72,7 @@ void Log::d(const char* message, ...)
|
|
|
{
|
|
|
va_list args;
|
|
|
va_start (args, message);
|
|
|
- log_message(LL_DEBUG, message, args);
|
|
|
+ log_message(LogSeverity::DEBUG, message, args);
|
|
|
va_end (args);
|
|
|
}
|
|
|
|
|
|
@@ -89,7 +81,7 @@ void Log::e(const char* message, ...)
|
|
|
{
|
|
|
va_list args;
|
|
|
va_start (args, message);
|
|
|
- log_message(LL_ERROR, message, args);
|
|
|
+ log_message(LogSeverity::ERROR, message, args);
|
|
|
va_end (args);
|
|
|
}
|
|
|
|
|
|
@@ -98,7 +90,7 @@ void Log::w(const char* message, ...)
|
|
|
{
|
|
|
va_list args;
|
|
|
va_start (args, message);
|
|
|
- log_message(LL_WARN, message, args);
|
|
|
+ log_message(LogSeverity::WARN, message, args);
|
|
|
va_end (args);
|
|
|
}
|
|
|
|
|
|
@@ -107,23 +99,8 @@ void Log::i(const char* message, ...)
|
|
|
{
|
|
|
va_list args;
|
|
|
va_start (args, message);
|
|
|
- log_message(LL_INFO, message, args);
|
|
|
+ log_message(LogSeverity::INFO, message, args);
|
|
|
va_end (args);
|
|
|
}
|
|
|
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-void Log::flush()
|
|
|
-{
|
|
|
- os::printf(g_stream.c_str());
|
|
|
- ::fflush(stdout);
|
|
|
-
|
|
|
- if (device()->rpc() != NULL)
|
|
|
- {
|
|
|
- device()->rpc()->send_message_to_all(g_stream.c_str());
|
|
|
- }
|
|
|
-
|
|
|
- g_stream.clear();
|
|
|
- g_allocator.clear();
|
|
|
-}
|
|
|
-
|
|
|
} // namespace crown
|