[77] | 1 | /* $Id: logging.h 26 2011-10-17 07:04:33Z mmamonski $ */ |
---|
| 2 | /* |
---|
| 3 | * PSNC DRMAA 2.0 utilities library |
---|
| 4 | * Copyright (C) 2012 Poznan Supercomputing and Networking Center |
---|
| 5 | * |
---|
| 6 | * This program is free software: you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #ifndef __DRMAA_UTILS__LOGGING_H |
---|
| 21 | #define __DRMAA_UTILS__LOGGING_H |
---|
| 22 | |
---|
| 23 | #ifdef HAVE_CONFIG_H |
---|
| 24 | # include <config.h> |
---|
| 25 | #endif |
---|
| 26 | |
---|
| 27 | #include <stdio.h> |
---|
| 28 | |
---|
| 29 | #include <drmaa_utils/compat.h> |
---|
| 30 | #include <drmaa_utils/util.h> |
---|
| 31 | |
---|
| 32 | #define _log_fmt(level, kind, args) \ |
---|
| 33 | do { \ |
---|
| 34 | if( (int)fsd_verbose_level <= level ) \ |
---|
| 35 | _fsd_log( level, __FILE__, __FUNCTION__, kind, \ |
---|
| 36 | fsd_asprintf args ); \ |
---|
| 37 | } while(0) |
---|
| 38 | |
---|
| 39 | #define _log_empty(level, kind) \ |
---|
| 40 | do { \ |
---|
| 41 | if( (int)fsd_verbose_level <= level ) \ |
---|
| 42 | _fsd_log( level, __FILE__, __FUNCTION__, kind, NULL ); \ |
---|
| 43 | } while(0) |
---|
| 44 | |
---|
| 45 | #define _log_nop \ |
---|
| 46 | do { /* nothing */ } while(0) |
---|
| 47 | |
---|
| 48 | #ifdef DEBUGGING |
---|
| 49 | # define fsd_log_trace(args) _log_fmt(FSD_LOG_TRACE, _FSD_LOG_MSG, args) |
---|
| 50 | # define fsd_log_debug(args) _log_fmt(FSD_LOG_DEBUG, _FSD_LOG_MSG, args) |
---|
| 51 | # define fsd_log_enter(args) _log_fmt(FSD_LOG_TRACE, _FSD_LOG_ENTER, args) |
---|
| 52 | # define fsd_log_return(args) _log_fmt(FSD_LOG_TRACE, _FSD_LOG_RETURN, args) |
---|
| 53 | #else /* ! DEBUGGING */ |
---|
| 54 | # define fsd_log_trace(args) _log_nop |
---|
| 55 | # define fsd_log_debug(args) _log_nop |
---|
| 56 | # define fsd_log_enter(args) _log_nop |
---|
| 57 | # define fsd_log_return(args) _log_nop |
---|
| 58 | #endif |
---|
| 59 | |
---|
| 60 | #define fsd_log_info(args) _log_fmt(FSD_LOG_INFO, _FSD_LOG_MSG, args) |
---|
| 61 | #define fsd_log_warning(args) _log_fmt(FSD_LOG_WARNING, _FSD_LOG_MSG, args) |
---|
| 62 | #define fsd_log_error(args) _log_fmt(FSD_LOG_ERROR, _FSD_LOG_MSG, args) |
---|
| 63 | #define fsd_log_fatal(args) _log_fmt(FSD_LOG_FATAL, _FSD_LOG_MSG, args) |
---|
| 64 | |
---|
| 65 | enum{ _FSD_LOG_MSG, _FSD_LOG_ENTER, _FSD_LOG_RETURN }; |
---|
| 66 | void _fsd_log( int level, const char *file, const char *function, |
---|
| 67 | int kind, char *message ); |
---|
| 68 | |
---|
| 69 | void fsd_log_fmt( int level, const char *fmt, ... ) |
---|
| 70 | __attribute__(( format( printf, 2, 3 ) )); |
---|
| 71 | |
---|
| 72 | void fsd_log_fmtv( int level, const char *fmt, va_list args ); |
---|
| 73 | |
---|
| 74 | void fsd_log_stacktrace( int skip, int limit ); |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * Specify place where log messages shall be written. |
---|
| 78 | * By default they are written to standard error stream (2). |
---|
| 79 | * @param fd File descriptor to write to. |
---|
| 80 | */ |
---|
| 81 | void |
---|
| 82 | fsd_set_logging_fd( int fd ); |
---|
| 83 | |
---|
| 84 | typedef enum { |
---|
| 85 | FSD_LOG_ALL, |
---|
| 86 | FSD_LOG_TRACE, |
---|
| 87 | FSD_LOG_DEBUG, |
---|
| 88 | FSD_LOG_INFO, |
---|
| 89 | FSD_LOG_WARNING, |
---|
| 90 | FSD_LOG_ERROR, |
---|
| 91 | FSD_LOG_FATAL, |
---|
| 92 | FSD_LOG_NONE |
---|
| 93 | } fsd_verbose_level_t; |
---|
| 94 | |
---|
| 95 | void fsd_set_verbosity_level( fsd_verbose_level_t level ); |
---|
| 96 | |
---|
| 97 | extern fsd_verbose_level_t fsd_verbose_level; |
---|
| 98 | |
---|
| 99 | #endif /* __DRMAA_UTILS__LOGGING_H */ |
---|
| 100 | |
---|