appkit  1.5.1
RoadNarrows Robotics Application Kit
LogStream.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_appkit
8 //
9 // File: LogStream.h
10 //
11 /*! \file
12  *
13  * \brief Logging facitlities built on librnr log.h macros to support C++
14  * output insertion streaming.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  *
23  * \par License:
24  * MIT
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Permission is hereby granted, without written agreement and without
30  * license or royalty fees, to use, copy, modify, and distribute this
31  * software and its documentation for any purpose, provided that
32  * (1) The above copyright notice and the following two paragraphs
33  * appear in all copies of the source code and (2) redistributions
34  * including binaries reproduces these notices in the supporting
35  * documentation. Substantial modifications to this software may be
36  * copyrighted by their authors and need not follow the licensing terms
37  * described here, provided that the new terms are clearly indicated in
38  * all files where they apply.
39  *
40  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
41  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
42  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
43  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
44  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
45  * THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
49  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
50  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
52  *
53  * @EulaEnd@
54  */
55 ////////////////////////////////////////////////////////////////////////////////
56 
57 #ifndef _RNR_LOG_STREAM_H
58 #define _RNR_LOG_STREAM_H
59 
60 #include <unistd.h>
61 #include <stdlib.h>
62 #include <stdio.h>
63 
64 #include <iostream>
65 #include <sstream>
66 #include <string>
67 
68 #include "rnr/rnrconfig.h"
69 #include "rnr/log.h"
70 
71 /*!
72  * \brief User diagnostic stream logging.
73  * \param level Logging user level.
74  * \param args Stream arguments arg [<< arg [<< ...]].
75  */
76 #define LOGUSER_STREAM(level, args) \
77  do \
78  { \
79  stringstream ss; \
80  ss << args; \
81  LOGUSER(level, "%s", ss.str().c_str()); \
82  } \
83  while(0)
84 
85 /*!
86  * \brief Diagnostic level 5 stream logging.
87  * \param args Stream arguments arg [<< arg [<< ...]].
88  */
89 #define LOGDIAG5_STREAM(args) \
90  do \
91  { \
92  stringstream ss; \
93  ss << args; \
94  LOGDIAG5("%s", ss.str().c_str()); \
95  } \
96  while(0)
97 
98 /*!
99  * \brief Diagnostic level 4 stream logging.
100  * \param args Stream arguments arg [<< arg [<< ...]].
101  */
102 #define LOGDIAG4_STREAM(args) \
103  do \
104  { \
105  stringstream ss; \
106  ss << args; \
107  LOGDIAG4("%s", ss.str().c_str()); \
108  } \
109  while(0)
110 
111 /*!
112  * \brief Diagnostic level 3 stream logging.
113  * \param args Stream arguments arg [<< arg [<< ...]].
114  */
115 #define LOGDIAG3_STREAM(args) \
116  do \
117  { \
118  stringstream ss; \
119  ss << args; \
120  LOGDIAG3("%s", ss.str().c_str()); \
121  } \
122  while(0)
123 
124 /*!
125  * \brief Diagnostic level 2 stream logging.
126  * \param args Stream arguments arg [<< arg [<< ...]].
127  */
128 #define LOGDIAG2_STREAM(args) \
129  do \
130  { \
131  stringstream ss; \
132  ss << args; \
133  LOGDIAG2("%s", ss.str().c_str()); \
134  } \
135  while(0)
136 
137 /*!
138  * \brief Diagnostic level 1 stream logging.
139  * \param args Stream arguments arg [<< arg [<< ...]].
140  */
141 #define LOGDIAG1_STREAM(args) \
142  do \
143  { \
144  stringstream ss; \
145  ss << args; \
146  LOGDIAG1("%s", ss.str().c_str()); \
147  } \
148  while(0)
149 
150 /*!
151  * \brief Warning stream logging.
152  * \param args Stream arguments arg [<< arg [<< ...]].
153  */
154 #define LOGWARN_STREAM(args) \
155  do \
156  { \
157  stringstream ss; \
158  ss << args; \
159  LOGWARN("%s", ss.str().c_str()); \
160  } \
161  while(0)
162 
163 /*!
164  * \brief Error stream logging.
165  * \param args Stream arguments arg [<< arg [<< ...]].
166  */
167 #define LOGERROR_STREAM(args) \
168  do \
169  { \
170  stringstream ss; \
171  ss << args; \
172  LOGERROR("%s", ss.str().c_str()); \
173  } \
174  while(0)
175 
176 /*!
177  * \brief System Error stream logging.
178  * \param args Stream arguments arg [<< arg [<< ...]].
179  */
180 #define LOGSYSERROR_STREAM(args) \
181  do \
182  { \
183  stringstream ss; \
184  ss << args; \
185  LOGSYSERROR("%s", ss.str().c_str()); \
186  } \
187  while(0)
188 
189 
190 #endif // _RNR_LOG_STREAM_H