00001
00002 #define ML_DEBUG // always enable debug
00003
00004 #if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00005 # include "fhiclcpp/ParameterSet.h"
00006 # include "fhiclcpp/make_ParameterSet.h"
00007 # include <fstream>
00008 # include <sstream>
00009 #endif
00010 #include <iostream>
00011 #include <stdlib.h>
00012 #include <cstdio>
00013
00014 #include "messagefacility/MessageLogger/MessageLogger.h"
00015
00016 void anotherLogger()
00017 {
00018
00019 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00020 mf::SetApplicationName("anotherLogger");
00021 # else
00022 mf::SetModuleName("anotherLogger");
00023 # endif
00024
00025 mf::LogWarning("warn1 | warn2") << "Followed by a WARNING message.";
00026 mf::LogDebug("debug") << "The debug message in the other thread";
00027
00028 return;
00029 }
00030
00031 int main()
00032 {
00033 try
00034 {
00035
00036 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00037 std::ostringstream ss;
00038 std::ifstream logfhicl("MessageFacility.cfg");
00039 if (logfhicl.is_open()) {
00040 std::stringstream fhiclstream;
00041 fhiclstream << logfhicl.rdbuf();
00042 ss << fhiclstream.str();
00043 }
00044 fhicl::ParameterSet pset;
00045 std::string pstr(ss.str());
00046 fhicl::make_ParameterSet(pstr, pset);
00047 mf::StartMessageFacility( pset );
00048 # else
00049 mf::StartMessageFacility(
00050 mf::MessageFacilityService::MultiThread,
00051 mf::MessageFacilityService::ConfigurationFile(
00052 "MessageFacility.cfg",
00053 mf::MessageFacilityService::logCF("mylog")));
00054 # endif
00055 }
00056 catch (std::exception& e)
00057 {
00058 std::cerr << "Catched\n" << e.what();
00059 exit(-1);
00060 }
00061
00062
00063 mf::SetApplicationName("mftest");
00064 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00065 mf::SetModuleName("MFTest");
00066 mf::SetContext("pre-event");
00067 # endif
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00078 mf::SetContext("pro-event");
00079 # endif
00080
00081
00082
00083 char buf[100];
00084
00085
00086 for (int i = 0; i < 2; ++i)
00087 {
00088 if (i % 1000 == 0)
00089 {
00090 sprintf(buf, "mftest-%d", i);
00091 mf::SetApplicationName(buf);
00092 }
00093
00094 mf::LogError("catError") << "Error information. " << i;
00095 mf::LogWarning("catWarning") << "Warning information. " << i;
00096 mf::LogInfo("catInfo") << "Info information. " << i;
00097 LOG_DEBUG("debug") << "DEBUG information. " << i;
00098
00099
00100 usleep(400000);
00101 }
00102
00103
00104
00105
00106 mf::LogStatistics();
00107
00108
00109
00110 return 0;
00111 }