StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StWsAppender.cxx
1 
2 #include "StWsAppender.h"
3 #include "TSystem.h"
4 #include "TString.h"
5 
6 #include "StWsLogger.h"
7 #include "picojson.h"
8 
9 #include <log4cxx/helpers/loglog.h>
10 #include <log4cxx/helpers/optionconverter.h>
11 #include <log4cxx/patternlayout.h>
12 
13 
14 using namespace log4cxx;
15 using namespace log4cxx::helpers;
16 using namespace log4cxx::db;
17 using namespace log4cxx::spi;
18 
19 IMPLEMENT_LOG4CXX_OBJECT(StWsAppender)
20 
21 //_________________________________________________________________________
23 {
24 
25 }
26 
27 //_________________________________________________________________________
28 StWsAppender::~StWsAppender()
29 {
30  finalize();
31 }
32 
33 //_________________________________________________________________________
34 void StWsAppender::setOption(const String& option,
35  const String& value)
36 {
37  if (equalsIgnoreCase(option, _T("WS_TASK_ID")))
38  {
39  StWsLoggerS::Instance().setTaskID(value);
40  } else if (equalsIgnoreCase(option, _T("WS_JOB_ID"))) {
41  StWsLoggerS::Instance().setJobID(value);
42  } else if (equalsIgnoreCase(option, _T("WS_LOG_URL"))) {
43  StWsLoggerS::Instance().setServiceUrl(value);
44  }
45  else
46  {
47  AppenderSkeleton::setOption(name, value);
48  }
49 }
50 
51 //_________________________________________________________________________
52 void StWsAppender::append(const spi::LoggingEventPtr& event)
53 {
54  time_t time = event->getTimeStamp();
55  const LevelPtr& lvl = event->getLevel();
56  const String& msg = event->getMessage();
57 
58  StWsLogger::LEVEL log_level = StWsLogger::INFO;
59 
60  if (lvl == LOG4CXX_LEVEL_FATAL) {
61  log_level = StWsLogger::FATAL;
62  } else if (lvl == LOG4CXX_LEVEL_ERROR) {
63  log_level = StWsLogger::ERROR;
64  } else if (lvl == LOG4CXX_LEVEL_WARN) {
65  log_level = StWsLogger::WARNING;
66  } else if (lvl == LOG4CXX_LEVEL_DEBUG) {
67  log_level = StWsLogger::DEBUG;
68  } else {
69  //return; // FIXME
70  }
71 
72  picojson::object evt;
73  evt["timestamp"] = picojson::value((double)time);
74  evt["msg_line"] = picojson::value(msg.c_str());
75 
76  StWsLoggerS::Instance().logEvent(log_level, evt, StWsLogger::STATUS);
77 }
78 
79 //_________________________________________________________________________
80 String StWsAppender::getLogStatement(const spi::LoggingEventPtr& event)
81 {
82 #if (STAR_LOG4CXX_VERSION == 9)
83  StringBuffer sbuf;
84  ((StWsAppender*)this)->getLayout()->format(sbuf, event);
85  return sbuf.str();
86 #else
87  String sbuf;
88  ((StWsAppender*)this)->getLayout()->format(sbuf, event,pool);
89  return sbuf;
90 #endif
91 }
92 
93 //_________________________________________________________________________
94 void StWsAppender::close()
95 {
96  this->closed = true;
97 }
98 
99 
100 #if (STAR_LOG4CXX_VERSION == 10)
101 //_________________________________________________________________________
102 void StWsAppender::append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p)
103 {
104  append(event);
105 }
106 #endif
107