log_streams.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <iostream>
13 #include <string>
14 #include <ecl/threads/thread.hpp>
16 
17 /*****************************************************************************
18 ** Using
19 *****************************************************************************/
20 
21 using std::string;
22 using ecl::New;
23 using ecl::LogStream;
24 using ecl::Thread;
25 
26 /*****************************************************************************
27 ** Namespaces
28 *****************************************************************************/
29 
30 namespace ecl {
31 namespace demos {
32 
33 /*****************************************************************************
34 ** Enums
35 *****************************************************************************/
36 
37 enum LogModes {
41 };
42 
43 void enableModes( LogStream &log_stream ) {
44  log_stream.enableHeader();
45  log_stream.enableTimeStamp();
46  log_stream.enableMode(Warning,"WARNING");
47  log_stream.enableMode(Error,"ERROR");
48  log_stream.enableMode(Debug,"DEBUG");
49 }
50 
51 void f() {
52  LogStream logstream("test.log",New);
53  enableModes(logstream);
54  LOG(logstream,Debug) << "Debug message from a threaded function.\n";
55  FLUSH(logstream);
56 }
57 
58 } // namespace demos
59 } // namespace ecl
60 
61 /*****************************************************************************
62 ** Using
63 *****************************************************************************/
64 
65 using namespace ecl::demos;
66 
67 /*****************************************************************************
68 ** Main
69 *****************************************************************************/
70 
71 int main(int argc, char** argv) {
72 
73  std::cout << std::endl;
74  std::cout << "***********************************************************" << std::endl;
75  std::cout << " LogStream" << std::endl;
76  std::cout << "***********************************************************" << std::endl;
77  std::cout << std::endl;
78 
79  std::cout << "This program will log from main and a parallel thread" << std::endl;
80  std::cout << "to a shared log file call 'test.log'." << std::endl;
81 
82  LogStream logstream("test.log",New);
83  enableModes(logstream);
84  Thread thread(f);
85  LOG(logstream,Debug) << "Debug message from main.\n";
86  FLUSH(logstream);
87  thread.join();
88 
89  std::cout << std::endl;
90  std::cout << "***********************************************************" << std::endl;
91  std::cout << " Passed" << std::endl;
92  std::cout << "***********************************************************" << std::endl;
93  std::cout << std::endl;
94 
95  return 0;
96 }
void enableModes(LogStream &log_stream)
Definition: log_streams.cpp:43
void enableMode(int mode, const std::string header="")
Enable the given mode and associate the specified header.
Definition: log_stream.cpp:37
A customised textstream for fast, multithreaded logging to file.
Definition: log_stream.hpp:110
Macro enabled, fast logging stream.
void enableHeader()
Enable header information.
Definition: log_stream.cpp:32
void enableTimeStamp()
Enable time stamps.
Definition: log_stream.cpp:34
EndOfLine endl
int main(int argc, char **argv)
Definition: log_streams.cpp:71


ecl_streams
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:59:07