00001 #include <sstream>
00002 #include <iostream>
00003 #include <fstream>
00004 #include <regex.h>
00005 #include <cstring>
00006
00007 #include "TxEventLogFactory.h"
00008 #include "TxEventLogWeb.h"
00009 #include "TxEventLogCollector.h"
00010
00011 using namespace TxLogging;
00012
00013
00014 TxEventLog* TxEventLogFactory::create(const char *technology)
00015 {
00016 TxEventLog *log = 0;
00017 if (technology && (*technology=='w' || *technology=='W' ))
00018 log= new TxEventLogWeb;
00019 else if (technology && (*technology=='c' || *technology=='C'|| *technology=='U' || *technology=='u' ))
00020 log= new TxEventLogCollector;
00021 else
00022 log=new TxEventLogFile;
00023 return log;
00024 }
00025
00026 using namespace std;
00027 namespace {
00053
00054 static void log(const char *key, const char *value)
00055 {
00056 using namespace TxLogging;
00057 printf("\" %s \"=\"%s\"", key, value);
00058
00059 const char * ucmCollector = "ucm";
00060 TxEventLog *eventLog = TxEventLogFactory::create(ucmCollector);
00061
00062
00063 if(! strcmp(key,"JobSubmitState")){
00064
00065 if(!strcmp(value, "STAGEIN")){
00066 eventLog->setJobSubmitState(TxEventLog::STAGEIN);
00067 }else if(!strcmp(value,"ACTIVE")){
00068 eventLog->setJobSubmitState(TxEventLog::ACTIVE);
00069 }else if(!strcmp(value, "DONE")){
00070 eventLog->setJobSubmitState(TxEventLog::DONE);
00071 }
00072
00073 }else{
00074
00075 eventLog->logStart(key, value);
00076 }
00077 }
00078
00079 int Main(int argc, const char *argv[])
00080 {
00081 string arg;
00082 while (--argc) arg += *(++argv);
00083 regex_t rgex1;
00084 regex_t rgex2;
00085 char errtext[512]={0};
00086 int errcode = 0;
00087
00088 const char *regX1 = "^ *([^ ]+) *= *([^ ]+.*[^ ]*) *$";
00089 const char *regX2 = "^ *-key *([^ ]+) *-value *([^ ]+.*[^ ]*) *$";
00090 regcomp(&rgex1,regX1,REG_ICASE | REG_EXTENDED);
00091 regcomp(&rgex2,regX2,REG_ICASE | REG_EXTENDED );
00092 regmatch_t matchptr [3];
00093 size_t nmatch = sizeof(matchptr)/sizeof(regmatch_t);
00094 if (! (errcode = regexec(&rgex1,arg.c_str(),nmatch,matchptr,0) ) ) {
00095 string key = arg.substr(matchptr[1].rm_so, matchptr[1].rm_eo-matchptr[1].rm_so );
00096 string value = arg.substr(matchptr[2].rm_so, matchptr[2].rm_eo-matchptr[2].rm_so );
00097 log(key.c_str(), value.c_str());
00098 } else if (! regexec(&rgex2,arg.c_str(),nmatch,matchptr,0) ) {
00099 string key = arg.substr(matchptr[1].rm_so, matchptr[1].rm_eo-matchptr[1].rm_so );
00100 string value = arg.substr(matchptr[2].rm_so, matchptr[2].rm_eo-matchptr[2].rm_so );
00101 log(key.c_str(), value.c_str());
00102 } else{
00103 const char *usage = " Input format error\n"
00104 "\n"
00105 "Usage:\n"
00106 "\n"
00107 " ulog -key [key] -value [value]\n"
00108 "or\n"
00109 " ulog [key]=[value]\n"
00110 "\n";
00111 printf("\n%s: %s\n",arg.c_str(),usage);
00112 return 1;
00113 }
00114 regfree(&rgex1);
00115 regfree(&rgex2);
00116 return 0;
00117 }
00118 }
00119
00120
00121 int TxEventLogFactory::main(int argc, const char *argv[])
00122 {
00123 return Main(argc, argv);
00124 }