File: logger.cpp

package info (click to toggle)
mcrl2 201409.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd
  • size: 46,348 kB
  • ctags: 29,960
  • sloc: cpp: 213,160; ansic: 16,219; python: 13,238; yacc: 309; lex: 214; xml: 197; makefile: 83; sh: 82; pascal: 17
file content (49 lines) | stat: -rwxr-xr-x 1,440 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define MCRL2_MAX_LOG_LEVEL debug3
#include "mcrl2/utilities/logger.h"

using namespace mcrl2::log;

void do_something_special()
{
  mCRL2log(debug3, "my_algorithm") << "doing something special" << std::endl;
}

std::string my_algorithm()
{
  mCRL2log(debug, "my_algorithm") << "Starting my_algorithm" << std::endl;
  int iterations = 3;
  mCRL2log(debug1, "my_algorithm") << "A loop with " << iterations << " iterations" << std::endl;
  for(int i = 0; i < iterations; ++i)
  {
    mCRL2log(debug2, "my_algorithm") << "Iteration " << i << std::endl;
    if(i >= 2)
    {
      mCRL2log(debug3, "my_algorithm") << "iteration number >= 2, treating specially" << std::endl;
      do_something_special();
    }
  }
  return "my_algorithm";
}

int main(int /*argc*/, char** /*argv*/)
{
  mcrl2_logger::set_reporting_level(debug3);

  mCRL2log(info) << "This shows the way info messages are printed, using the default messages" << std::endl;
  mCRL2log(debug) << "This line is not printed, and the function " << my_algorithm() << " is not evaluated" << std::endl;

  FILE* plogfile;
  plogfile = fopen("logger_test_file.txt" , "w");
  if(plogfile == NULL)
  {
    throw std::runtime_error("Cannot open logfile for writing");
  }
  file_output::set_stream(plogfile, "my_algorithm");
  mcrl2_logger::set_reporting_level(debug3, "my_algorithm");

  // Execute algorithm
  my_algorithm();

  // Do not forget to close the file.
  fclose(plogfile);
}