MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
macsio_log.h
Go to the documentation of this file.
1 #ifndef _MACSIO_LOG_H
2 #define _MACSIO_LOG_H
3 /*
4 Copyright (c) 2015, Lawrence Livermore National Security, LLC.
5 Produced at the Lawrence Livermore National Laboratory.
6 Written by Mark C. Miller
7 
8 LLNL-CODE-676051. All rights reserved.
9 
10 This file is part of MACSio
11 
12 Please also read the LICENSE file at the top of the source code directory or
13 folder hierarchy.
14 
15 This program is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License (as published by the Free Software
17 Foundation) version 2, dated June 1991.
18 
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the terms and conditions of the GNU General
22 Public License for more details.
23 
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
26 Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28 
29 #ifdef HAVE_MPI
30 #include <mpi.h>
31 #endif
32 
33 #include <errno.h>
34 #include <stdio.h>
35 
91 #ifndef DOXYGEN_IGNORE_THIS /*[*/
92 
93 #ifdef HAVE_MPI
94 #define MACSIO_LOG_MSG2(LOG, MSG, SEVVAL, SEVSTR, ERRNO, MPI_ERRNO, THEFILE, THELINE) \
95 do{ \
96  MACSIO_LOG_LogMsgWithDetails(LOG, MACSIO_LOG_MakeMsg MSG, SEVVAL, SEVSTR, ERRNO, \
97  MPI_ERRNO, THEFILE, THELINE); \
98  ERRNO = 0; \
99  MPI_ERRNO = MPI_SUCCESS; \
100 }while(0)
101 #else
102 #define MACSIO_LOG_MSG2(LOG, MSG, SEVVAL, SEVSTR, ERRNO, MPI_ERRNO, THEFILE, THELINE) \
103 do{ \
104  MACSIO_LOG_LogMsgWithDetails(LOG, MACSIO_LOG_MakeMsg MSG, SEVVAL, SEVSTR, ERRNO, \
105  MPI_ERRNO, THEFILE, THELINE); \
106  ERRNO = 0; \
107 }while(0)
108 #endif
109 
110 #endif /*] DOXYGEN_IGNORE_THIS */
111 
115 #define MACSIO_LOG_DEFAULT_LINE_COUNT 64
116 
120 #define MACSIO_LOG_DEFAULT_EXTRA_LINES 64
121 
125 #define MACSIO_LOG_DEFAULT_LINE_LENGTH 128
126 
133 #define MACSIO_LOG_MSG(SEV, MSG) MACSIO_LOG_MSG2(MACSIO_LOG_MainLog, MSG, MACSIO_LOG_Msg ## SEV, #SEV, errno, mpi_errno, __FILE__, __LINE__)
134 
141 #define MACSIO_LOG_MSGV(VSEV, MSG) \
142 do \
143 { \
144  switch (VSEV) \
145  { \
146  case MACSIO_LOG_MsgDbg1: {MACSIO_LOG_MSG(Dbg1, MSG); break;} \
147  case MACSIO_LOG_MsgDbg2: {MACSIO_LOG_MSG(Dbg2, MSG); break;} \
148  case MACSIO_LOG_MsgDbg3: {MACSIO_LOG_MSG(Dbg3, MSG); break;} \
149  case MACSIO_LOG_MsgInfo: {MACSIO_LOG_MSG(Info, MSG); break;} \
150  case MACSIO_LOG_MsgWarn: {MACSIO_LOG_MSG(Warn, MSG); break;} \
151  case MACSIO_LOG_MsgErr: {MACSIO_LOG_MSG(Err, MSG); break; } \
152  case MACSIO_LOG_MsgDie: {MACSIO_LOG_MSG(Die, MSG); break; } \
153  } \
154 }while(0)
155 
163 #define MACSIO_LOG_MSGL(LOG, SEV, MSG) MACSIO_LOG_MSG2(LOG, MSG, MACSIO_LOG_Msg ## SEV, #SEV, errno, mpi_errno, __FILE__, __LINE__)
164 
172 #define MACSIO_LOG_MSGLV(LOG, VSEV, MSG) \
173 do \
174 { \
175  switch (VSEV) \
176  { \
177  case MACSIO_LOG_MsgDbg1: {MACSIO_LOG_MSGL(LOG, Dbg1, MSG); break;} \
178  case MACSIO_LOG_MsgDbg2: {MACSIO_LOG_MSGL(LOG, Dbg2, MSG); break;} \
179  case MACSIO_LOG_MsgDbg3: {MACSIO_LOG_MSGL(LOG, Dbg3, MSG); break;} \
180  case MACSIO_LOG_MsgInfo: {MACSIO_LOG_MSGL(LOG, Info, MSG); break;} \
181  case MACSIO_LOG_MsgWarn: {MACSIO_LOG_MSGL(LOG, Warn, MSG); break;} \
182  case MACSIO_LOG_MsgErr: {MACSIO_LOG_MSGL(LOG, Err, MSG); break; } \
183  case MACSIO_LOG_MsgDie: {MACSIO_LOG_MSGL(LOG, Die, MSG); break; } \
184  } \
185 }while(0)
186 
187 #ifdef __cplusplus
188 extern "C" {
189 #endif
190 
192 {
201 
203 
214 extern int mpi_errno;
215 
231 extern int MACSIO_LOG_DebugLevel;
232 
240 
241 
249 
250 extern char const * MACSIO_LOG_MakeMsg(const char *format, ...);
251 #ifdef HAVE_MPI
252 extern MACSIO_LOG_LogHandle_t *MACSIO_LOG_LogInit(MPI_Comm comm, char const *path, int line_len, int lines_per_proc, int extra_lines_proc0);
253 #else
254 extern MACSIO_LOG_LogHandle_t *MACSIO_LOG_LogInit(int comm, char const *path, int line_len, int lines_per_proc, int extra_lines_proc0);
255 #endif
256 extern void MACSIO_LOG_LogMsg(MACSIO_LOG_LogHandle_t const *log, char const *fmt, ...);
257 extern void MACSIO_LOG_LogMsgWithDetails(MACSIO_LOG_LogHandle_t const *log, char const *linemsg,
258  MACSIO_LOG_MsgSeverity_t sevVal, char const *sevStr,
259  int sysErrno, int mpiErrno, char const *theFile, int theLine);
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
268 #endif /* _MACSIO_LOG_H */
MACSIO_LOG_LogHandle_t * MACSIO_LOG_StdErr
Log handle for MACSIO's stderr output.
Definition: macsio_log.c:46
char const * MACSIO_LOG_MakeMsg(char const *format,...)
Internal convenience method to build a message from a printf-style format string and args...
Definition: macsio_log.c:79
int mpi_errno
Error code returned by most recent MPI call.
Definition: macsio_log.c:43
MACSIO_LOG_LogHandle_t * MACSIO_LOG_LogInit(MPI_Comm comm, char const *path, int line_len, int lines_per_proc, int extra_lines_proc0)
Initialize a log.
Definition: macsio_log.c:113
enum _MACSIO_LOG_MsgSeverity_t MACSIO_LOG_MsgSeverity_t
void MACSIO_LOG_LogFinalize(MACSIO_LOG_LogHandle_t *log)
Finalize and close an open log Should be called collectively by all processors that created the log...
Definition: macsio_log.c:295
int MACSIO_LOG_DebugLevel
Definition: macsio_log.c:44
MACSIO_LOG_LogHandle_t * MACSIO_LOG_MainLog
Log handle for MACSIO's main log.
Definition: macsio_log.c:45
void MACSIO_LOG_LogMsg(MACSIO_LOG_LogHandle_t const *log, char const *fmt,...)
Issue a printf-style message to a log.
Definition: macsio_log.c:186
void MACSIO_LOG_LogMsgWithDetails(MACSIO_LOG_LogHandle_t const *log, char const *linemsg, MACSIO_LOG_MsgSeverity_t sevVal, char const *sevStr, int sysErrno, int mpiErrno, char const *theFile, int theLine)
Convenience method for building a detailed message for a log.
Definition: macsio_log.c:249
_MACSIO_LOG_MsgSeverity_t
Definition: macsio_log.h:191