#include "commore/Commore.h"
#include "commore/Error.h"
#include "commore/Tuple.h"
#include "commore/LogHook.h"
#include "commore/CriticalSection.h"
#include <stdio.h>
CMR_MODULE_DECLARE("EXAMPLE_LOGS");
CMR_FILE_DECLARE();
CMR_LOG_DECLARE(MYLOG);
using namespace std;
using namespace commore;
struct MyLogHookImpl :
public LogHook
{
MyLogHookImpl()
{
hook();
}
{
printf(
"My log hook message:level=%d key=%s\n", message.
get_int(
"level"), (
const char*)message.
get_astring(
"key"));
}
static AutoRefBase auto_create() {
return new MyLogHookImpl(); }
};
int main(int argc, const char* argv[])
{
int r = 0;
int num = 0;
init();
GlobVarLog::get_names("CMR", names);
cmr_foreach(
Symbol, name, names)
{
printf(" log:%s\n", name.get_name().c_str());
}
MyLogHook my_hook;
CMR_INFO("Start example Logs");
int c = 'h';
while (c != '.')
{
if (c == 'h')
{
printf("h : this message\n");
printf("l : create a LOG message\n");
printf("L : create a LOG message on MYLOG flag\n");
printf("2 : create a LOG2 message\n");
printf("3 : create a LOG3 message\n");
printf("e : create a ERR message\n");
printf("w : create a WARNING message\n");
printf("i : create a INFO message\n");
printf("u : UP LOG level\n");
printf("d : DOWN LOG level\n");
printf("U : UP MYLOG LOG level\n");
printf("d : DOWN MYLOG LOG level\n");
} else if (c == 'l')
{
CMR_LOG("This is a log message num: %0") << num++;
} else if (c == 'L')
{
CMR_NLOG(MYLOG, "This is a log message num: %0") << num++;
} else if (c == '2')
{
CMR_LOG2("This is a log message num: %0") << num++;
} else if (c == '3')
{
CMR_LOG3("This is a log message num: %0") << num++;
} else if (c == 'e')
{
CMR_ERROR("This is an error message num: %0") << num++;
} else if (c == 'w')
{
CMR_WARNING("This is a warning message num: %0") << num++;
} else if (c == 'i')
{
CMR_INFO("This is an info message num: %0") << num++;
} else if (c == 'u')
{
GlobVarLog::set("CMR", "LOGS", GlobVarLog::get("CMR", "LOGS") +1);
CMR_INFO("Log level set to %0") << GlobVarLog::get("CMR", "LOGS");
} else if (c == 'U')
{
GlobVarLog::set("CMR", "MYLOG", GlobVarLog::get("CMR", "MYLOG") +1);
CMR_INFO("MYLOG Log level set to %0") << GlobVarLog::get("CMR", "MYLOG");
} else if (c == 'd')
{
if (GlobVarLog::get("CMR", "LOGS") > 0)
{
GlobVarLog::set("CMR", "LOGS", GlobVarLog::get("CMR", "LOGS") - 1);
CMR_INFO("Log level set to %0") << GlobVarLog::get("CMR", "LOGS");
}
} else if (c == 'D')
{
if (GlobVarLog::get("CMR", "MYLOG") > 0)
{
GlobVarLog::set("CMR", "MYLOG", GlobVarLog::get("CMR", "MYLOG") - 1);
CMR_INFO("MYLOG Log level set to %0") << GlobVarLog::get("CMR", "MYLOG");
}
}
c = getchar();
}
CMR_INFO("Stop example Logs");
return r;
}