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 {
38  Warning,
39  Error,
40  Debug,
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 }
main
int main(int argc, char **argv)
Definition: log_streams.cpp:71
ecl::demos::Debug
@ Debug
Definition: log_streams.cpp:48
ecl::demos::Warning
@ Warning
Definition: log_streams.cpp:46
ecl::demos::f
void f()
Definition: log_streams.cpp:55
ecl::demos::LogModes
LogModes
Definition: log_streams.cpp:41
ecl::Error
ecl::LogStream::enableMode
void enableMode(int mode, const std::string header="")
Enable the given mode and associate the specified header.
Definition: log_stream.cpp:41
thread.hpp
ecl::New
New
ecl::endl
EndOfLine endl
Definition: manipulators.cpp:30
ecl::LogStream::enableHeader
void enableHeader()
Enable header information.
Definition: log_stream.cpp:36
ecl::demos
Definition: log_streams.cpp:33
ecl::LogStream
A customised textstream for fast, multithreaded logging to file.
Definition: log_stream.hpp:112
log_stream.hpp
Macro enabled, fast logging stream.
ecl::demos::Error
@ Error
Definition: log_streams.cpp:47
ecl::demos::enableModes
void enableModes(LogStream &log_stream)
Definition: log_streams.cpp:47
ecl
ecl::LogStream::enableTimeStamp
void enableTimeStamp()
Enable time stamps.
Definition: log_stream.cpp:38


ecl_streams
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:48