11c606a6 (kx 2023-04-11 01:18:34 +0300 1)
11c606a6 (kx 2023-04-11 01:18:34 +0300 2) /**********************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3)
11c606a6 (kx 2023-04-11 01:18:34 +0300 4) Copyright 2019 Andrey V.Kosteltsev
11c606a6 (kx 2023-04-11 01:18:34 +0300 5)
11c606a6 (kx 2023-04-11 01:18:34 +0300 6) Licensed under the Radix.pro License, Version 1.0 (the "License");
11c606a6 (kx 2023-04-11 01:18:34 +0300 7) you may not use this file except in compliance with the License.
11c606a6 (kx 2023-04-11 01:18:34 +0300 8) You may obtain a copy of the License at
11c606a6 (kx 2023-04-11 01:18:34 +0300 9)
11c606a6 (kx 2023-04-11 01:18:34 +0300 10) https://radix.pro/licenses/LICENSE-1.0-en_US.txt
11c606a6 (kx 2023-04-11 01:18:34 +0300 11)
11c606a6 (kx 2023-04-11 01:18:34 +0300 12) Unless required by applicable law or agreed to in writing, software
11c606a6 (kx 2023-04-11 01:18:34 +0300 13) distributed under the License is distributed on an "AS IS" BASIS,
11c606a6 (kx 2023-04-11 01:18:34 +0300 14) WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11c606a6 (kx 2023-04-11 01:18:34 +0300 15) implied.
11c606a6 (kx 2023-04-11 01:18:34 +0300 16)
11c606a6 (kx 2023-04-11 01:18:34 +0300 17) **********************************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 18)
11c606a6 (kx 2023-04-11 01:18:34 +0300 19) #ifndef _MSG_LOG_H_
11c606a6 (kx 2023-04-11 01:18:34 +0300 20) #define _MSG_LOG_H_
11c606a6 (kx 2023-04-11 01:18:34 +0300 21)
11c606a6 (kx 2023-04-11 01:18:34 +0300 22) #ifdef __cplusplus
11c606a6 (kx 2023-04-11 01:18:34 +0300 23) extern "C" {
11c606a6 (kx 2023-04-11 01:18:34 +0300 24) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 25)
11c606a6 (kx 2023-04-11 01:18:34 +0300 26) extern FILE *errlog;
11c606a6 (kx 2023-04-11 01:18:34 +0300 27)
11c606a6 (kx 2023-04-11 01:18:34 +0300 28) extern void (*fatal_error_hook)( void );
11c606a6 (kx 2023-04-11 01:18:34 +0300 29)
11c606a6 (kx 2023-04-11 01:18:34 +0300 30) extern char *program;
11c606a6 (kx 2023-04-11 01:18:34 +0300 31) extern int exit_status;
11c606a6 (kx 2023-04-11 01:18:34 +0300 32)
11c606a6 (kx 2023-04-11 01:18:34 +0300 33) enum _msg_type
11c606a6 (kx 2023-04-11 01:18:34 +0300 34) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 35) MSG_FATAL = 0,
11c606a6 (kx 2023-04-11 01:18:34 +0300 36) MSG_ERROR,
11c606a6 (kx 2023-04-11 01:18:34 +0300 37) MSG_WARNING,
11c606a6 (kx 2023-04-11 01:18:34 +0300 38) MSG_NOTICE,
11c606a6 (kx 2023-04-11 01:18:34 +0300 39) MSG_INFO,
11c606a6 (kx 2023-04-11 01:18:34 +0300 40) MSG_DEBUG,
11c606a6 (kx 2023-04-11 01:18:34 +0300 41)
11c606a6 (kx 2023-04-11 01:18:34 +0300 42) MSG_LOG
11c606a6 (kx 2023-04-11 01:18:34 +0300 43) };
11c606a6 (kx 2023-04-11 01:18:34 +0300 44)
11c606a6 (kx 2023-04-11 01:18:34 +0300 45) #define FATAL_ERROR( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 46) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 47) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 48) logmsg( errlog, MSG_FATAL, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 49) if( fatal_error_hook) fatal_error_hook(); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 50) exit( EXIT_FAILURE ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 51) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 52)
11c606a6 (kx 2023-04-11 01:18:34 +0300 53) #define ERROR( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 54) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 55) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 56) logmsg( errlog, MSG_ERROR, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 57) ++exit_status; \
11c606a6 (kx 2023-04-11 01:18:34 +0300 58) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 59)
11c606a6 (kx 2023-04-11 01:18:34 +0300 60) #define WARNING( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 61) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 62) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 63) logmsg( errlog, MSG_WARNING, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 64) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 65)
11c606a6 (kx 2023-04-11 01:18:34 +0300 66) #define NOTICE( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 67) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 68) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 69) logmsg( errlog, MSG_NOTICE, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 70) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 71)
11c606a6 (kx 2023-04-11 01:18:34 +0300 72) #define INFO( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 73) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 74) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 75) logmsg( errlog, MSG_INFO, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 76) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 77)
11c606a6 (kx 2023-04-11 01:18:34 +0300 78) #define DEBUG( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 79) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 80) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 81) logmsg( errlog, MSG_DEBUG, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 82) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 83)
11c606a6 (kx 2023-04-11 01:18:34 +0300 84) #define LOG( ... ) \
11c606a6 (kx 2023-04-11 01:18:34 +0300 85) do \
11c606a6 (kx 2023-04-11 01:18:34 +0300 86) { \
11c606a6 (kx 2023-04-11 01:18:34 +0300 87) logmsg( errlog, MSG_LOG, __VA_ARGS__ ); \
11c606a6 (kx 2023-04-11 01:18:34 +0300 88) } while (0)
11c606a6 (kx 2023-04-11 01:18:34 +0300 89)
11c606a6 (kx 2023-04-11 01:18:34 +0300 90)
11c606a6 (kx 2023-04-11 01:18:34 +0300 91) extern void logmsg( FILE *logfile, enum _msg_type type, char *format, ... );
11c606a6 (kx 2023-04-11 01:18:34 +0300 92)
11c606a6 (kx 2023-04-11 01:18:34 +0300 93)
11c606a6 (kx 2023-04-11 01:18:34 +0300 94) #ifdef __cplusplus
11c606a6 (kx 2023-04-11 01:18:34 +0300 95) } /* ... extern "C" */
11c606a6 (kx 2023-04-11 01:18:34 +0300 96) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 97)
11c606a6 (kx 2023-04-11 01:18:34 +0300 98) #endif /* _MSG_LOG_H_ */