125 lines
4.2 KiB
C++
125 lines
4.2 KiB
C++
/*
|
|
* CAMTP Responder
|
|
* Copyright (c) 2020 Holdtecs Technologies
|
|
*
|
|
* CAMTP Responder is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 3.0 of the License, or (at your option) any later version.
|
|
*
|
|
* CAMTP Responder is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License version 3 for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with CAMTP Responder; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
/**
|
|
* @file logs_out.h
|
|
* @brief Log output functions
|
|
* @author ***
|
|
*/
|
|
|
|
#ifndef _INC_DEBUG_OUT_H_
|
|
#define _INC_DEBUG_OUT_H_
|
|
#include "stringex.hpp"
|
|
#include "applog.h"
|
|
|
|
const std::string loggername = "camtprd";
|
|
|
|
void timestamp(char * timestr, int maxsize);
|
|
|
|
#define SIZEHEX PRIx64
|
|
#define DEBUG
|
|
#ifdef USE_SYSLOG
|
|
|
|
#include <syslog.h>
|
|
|
|
#else
|
|
|
|
#ifdef DEBUG
|
|
#include <stdio.h>
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef USE_SYSLOG // Syslog usage
|
|
|
|
#define PRINT_MSG(fmt, args...) syslog(LOG_NOTICE, "[CAMTPrd - Info] " fmt "\n", \
|
|
## args)
|
|
#define PRINT_ERROR(fmt, args...) syslog(LOG_ERR, "[CAMTPrd - Error] " fmt "\n", \
|
|
## args)
|
|
#define PRINT_WARN(fmt, args...) syslog(LOG_WARNING, "[CAMTPrd - Warning] " fmt "\n", \
|
|
## args)
|
|
#ifdef DEBUG
|
|
|
|
#define PRINT_DEBUG(fmt, args...) syslog(LOG_DEBUG, "[CAMTPrd - Debug] " fmt "\n", \
|
|
## args)
|
|
#else
|
|
|
|
#define PRINT_DEBUG(fmt, args...)
|
|
|
|
#endif
|
|
|
|
#else // Stdout usage
|
|
|
|
// #define PRINT_MSG(fmt, args...) { \
|
|
// char timestr[32]; \
|
|
// timestamp((char*)×tr, sizeof(timestr)); \
|
|
// fprintf(stdout, \
|
|
// "[CAMTPrd - %s - Info] " fmt "\n",(char*)×tr, \
|
|
// ## args); \
|
|
// fflush(stdout); \
|
|
// }
|
|
|
|
#define PRINT_MSG(fmt, args...) { \
|
|
char timestr[32]; \
|
|
timestamp((char*)×tr, sizeof(timestr)); \
|
|
LOG_INFO(string_format("[CAMTPrd - %s - Info] " fmt "\n",(char*)×tr, ## args)); \
|
|
}
|
|
|
|
|
|
#define PRINT_ERROR(fmt, args...) { \
|
|
char timestr[32]; \
|
|
timestamp((char*)×tr, sizeof(timestr)); \
|
|
LOG_ERROR(string_format("[CAMTPrd - %s - Info] " fmt "\n",(char*)×tr, ## args)); \
|
|
}
|
|
|
|
#define PRINT_WARN(fmt, args...) { \
|
|
char timestr[32]; \
|
|
timestamp((char*)×tr, sizeof(timestr)); \
|
|
LOG_WARN(string_format("[CAMTPrd - %s - Info] " fmt "\n",(char*)×tr, ## args)); \
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
#define PRINT_DEBUG(fmt, args...) { \
|
|
char timestr[32]; \
|
|
timestamp((char*)×tr, sizeof(timestr)); \
|
|
LOG_DEBUG(string_format("[CAMTPrd - %s - Info] " fmt "\n",(char*)×tr, ## args)); \
|
|
}
|
|
#else
|
|
|
|
#define PRINT_DEBUG(fmt, args...)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define PRINT_DEBUG_BUF(x, y) printbuf( x, y );
|
|
void printbuf(void * buf,int size);
|
|
|
|
#else
|
|
|
|
#define PRINT_DEBUG_BUF(x, y)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|