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