5 kx
5 kx /**********************************************************************
5 kx
5 kx Copyright 2019 Andrey V.Kosteltsev
5 kx
9 kx Licensed under the Radix cross Linux License, Version 1.0 .
5 kx you may not use this file except in compliance with the License.
5 kx You may obtain a copy of the License at
5 kx
9 kx https://radix-linux.su/licenses/LICENSE-1.0-en_US.txt
5 kx
5 kx Unless required by applicable law or agreed to in writing, software
5 kx distributed under the License is distributed on an "AS IS" BASIS,
5 kx WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
5 kx implied.
5 kx
5 kx **********************************************************************/
5 kx
5 kx #ifndef _MSG_LOG_H_
5 kx #define _MSG_LOG_H_
5 kx
5 kx #ifdef __cplusplus
5 kx extern "C" {
5 kx #endif
5 kx
5 kx extern FILE *errlog;
5 kx
5 kx extern void (*fatal_error_hook)( void );
5 kx
5 kx extern char *program;
5 kx extern int exit_status;
5 kx
5 kx enum _msg_type
5 kx {
5 kx MSG_FATAL = 0,
5 kx MSG_ERROR,
5 kx MSG_WARNING,
5 kx MSG_NOTICE,
5 kx MSG_INFO,
5 kx MSG_DEBUG,
5 kx
5 kx MSG_LOG
5 kx };
5 kx
5 kx #define FATAL_ERROR( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_FATAL, __VA_ARGS__ ); \
5 kx if( fatal_error_hook) fatal_error_hook(); \
5 kx exit( EXIT_FAILURE ); \
5 kx } while (0)
5 kx
5 kx #define ERROR( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_ERROR, __VA_ARGS__ ); \
5 kx ++exit_status; \
5 kx } while (0)
5 kx
5 kx #define WARNING( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_WARNING, __VA_ARGS__ ); \
5 kx } while (0)
5 kx
5 kx #define NOTICE( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_NOTICE, __VA_ARGS__ ); \
5 kx } while (0)
5 kx
5 kx #define INFO( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_INFO, __VA_ARGS__ ); \
5 kx } while (0)
5 kx
5 kx #define DEBUG( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_DEBUG, __VA_ARGS__ ); \
5 kx } while (0)
5 kx
5 kx #define LOG( ... ) \
5 kx do \
5 kx { \
5 kx logmsg( errlog, MSG_LOG, __VA_ARGS__ ); \
5 kx } while (0)
5 kx
5 kx
5 kx extern void logmsg( FILE *logfile, enum _msg_type type, char *format, ... );
5 kx
5 kx
5 kx #ifdef __cplusplus
5 kx } /* ... extern "C" */
5 kx #endif
5 kx
5 kx #endif /* _MSG_LOG_H_ */