Jpp  16.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMessageLogger.cc File Reference

Example program to test message logging. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JLogger/JStreamLogger.hh"
#include "JLogger/JControlHostLogger.hh"
#include "JLogger/JMessageLogger.hh"
#include "JLogger/JMessageStream.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Example program to test message logging.

Author
mdejong

Definition in file JMessageLogger.cc.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 20 of file JMessageLogger.cc.

21 {
22  using namespace std;
23 
24  string message_logger;
25  bool use_cout;
26  bool use_cin;
27  bool off;
28  int debug;
29 
30  try {
31 
32  JParser<> zap("Example program to test message logging.");
33 
34  zap['M'] = make_field(message_logger) = "localhost";
35  zap['c'] = make_field(use_cout);
36  zap['C'] = make_field(use_cin);
37  zap['x'] = make_field(off);
38  zap['d'] = make_field(debug) = 3;
39 
40  zap(argc, argv);
41  }
42  catch(const exception &error) {
43  FATAL(error.what() << endl);
44  }
45 
46  using namespace JPP;
47 
48  cout.tie(&cerr);
49 
50  JLogger* out = NULL;
51 
52  if (use_cout)
53  out = new JStreamLogger(cout);
54  else
55  out = new JControlHostLogger(message_logger);
56 
57  JMessageLogger logger(out, argv[0], debug);
58 
59  if (off) {
60  logger.setLevel(JMessageLogger::OFF);
61  }
62 
63  if (!use_cin) {
64 
65  logger.debug ("hello world");
66  logger.warning("hello world");
67  logger.error ("hello world");
68  logger.notice ("hello world");
69  logger.status ("hello world");
70 
71  JErrorStream(logger) << "hello" << ' ' << "world" << ' ' << hex << 15;
72 
73  } else {
74 
75  for (string buffer; ; ) {
76 
77  cout << "> " << flush;
78 
79  getline(cin, buffer);
80 
81  if (buffer != "")
82  logger.notice(buffer);
83  else
84  break;
85  }
86  }
87 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67