Commit c0486d50 authored by jehan's avatar jehan

migrate traces to bctbx

parent c8b49644
...@@ -70,15 +70,6 @@ do_stop() ...@@ -70,15 +70,6 @@ do_stop()
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?" RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2 [ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE rm -f $PIDFILE
return "$RETVAL" return "$RETVAL"
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "logmanager.hh" #include "logmanager.hh"
#include <string> #include <string>
#include <ortp/ortp.h> #include "bctoolbox/logging.h"
#include <syslog.h> #include <syslog.h>
using namespace std; using namespace std;
...@@ -30,22 +30,22 @@ bool sUseSyslog = false; ...@@ -30,22 +30,22 @@ bool sUseSyslog = false;
namespace flexisip { namespace flexisip {
namespace log { namespace log {
static void syslogHandler(const char *domain, OrtpLogLevel log_level, const char *str, va_list l) { static void syslogHandler(const char *domain, BctbxLogLevel log_level, const char *str, va_list l) {
int syslev = LOG_ALERT; int syslev = LOG_ALERT;
switch (log_level) { switch (log_level) {
case ORTP_DEBUG: case BCTBX_LOG_DEBUG:
syslev = LOG_DEBUG; syslev = LOG_DEBUG;
break; break;
case ORTP_MESSAGE: case BCTBX_LOG_MESSAGE:
syslev = LOG_INFO; syslev = LOG_INFO;
break; break;
case ORTP_WARNING: case BCTBX_LOG_WARNING:
syslev = LOG_WARNING; syslev = LOG_WARNING;
break; break;
case ORTP_ERROR: case BCTBX_LOG_ERROR:
syslev = LOG_ERR; syslev = LOG_ERR;
break; break;
case ORTP_FATAL: case BCTBX_LOG_FATAL:
syslev = LOG_ALERT; syslev = LOG_ALERT;
break; break;
default: default:
...@@ -54,22 +54,22 @@ namespace flexisip { ...@@ -54,22 +54,22 @@ namespace flexisip {
vsyslog(syslev, str, l); vsyslog(syslev, str, l);
} }
void defaultLogHandler(const char *domain, OrtpLogLevel log_level, const char *str, va_list l) { void defaultLogHandler(const char *domain, BctbxLogLevel log_level, const char *str, va_list l) {
const char *levname = "none"; const char *levname = "none";
switch (log_level) { switch (log_level) {
case ORTP_DEBUG: case BCTBX_LOG_DEBUG:
levname = "D: "; levname = "D: ";
break; break;
case ORTP_MESSAGE: case BCTBX_LOG_MESSAGE:
levname = "M: "; levname = "M: ";
break; break;
case ORTP_WARNING: case BCTBX_LOG_WARNING:
levname = "W: "; levname = "W: ";
break; break;
case ORTP_ERROR: case BCTBX_LOG_ERROR:
levname = "E: "; levname = "E: ";
break; break;
case ORTP_FATAL: case BCTBX_LOG_FATAL:
levname = "F: "; levname = "F: ";
break; break;
default: default:
...@@ -84,18 +84,17 @@ namespace flexisip { ...@@ -84,18 +84,17 @@ namespace flexisip {
is_preinit_done = true; is_preinit_done = true;
sUseSyslog = syslog; sUseSyslog = syslog;
is_debug = debug; is_debug = debug;
ortp_set_log_file(stdout);
if (debug) { if (debug) {
ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL); bctbx_set_log_level_mask(FLEXISIP_LOG_DOMAIN, BCTBX_LOG_DEBUG | BCTBX_LOG_MESSAGE | BCTBX_LOG_WARNING | BCTBX_LOG_ERROR | BCTBX_LOG_FATAL);
} else { } else {
ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL); bctbx_set_log_level_mask(FLEXISIP_LOG_DOMAIN, BCTBX_LOG_MESSAGE | BCTBX_LOG_WARNING | BCTBX_LOG_ERROR | BCTBX_LOG_FATAL);
} }
if (syslog) { if (syslog) {
openlog("flexisip", 0, LOG_USER); openlog("flexisip", 0, LOG_USER);
setlogmask(~0); setlogmask(~0);
ortp_set_log_handler(syslogHandler); bctbx_set_log_handler(syslogHandler);
} else { } else {
//ortp_set_log_handler(defaultLogHandler); //ortp_set_log_handler(defaultLogHandler);
} }
...@@ -110,9 +109,9 @@ namespace flexisip { ...@@ -110,9 +109,9 @@ namespace flexisip {
} }
if (debug) { if (debug) {
ortp_set_log_level(ORTP_LOG_DOMAIN, ORTP_DEBUG); bctbx_set_log_level_mask(FLEXISIP_LOG_DOMAIN, BCTBX_LOG_DEBUG);
} else { } else {
ortp_set_log_level(ORTP_LOG_DOMAIN, ORTP_WARNING); bctbx_set_log_level_mask(FLEXISIP_LOG_DOMAIN, BCTBX_LOG_WARNING);
} }
is_debug = debug; is_debug = debug;
...@@ -127,7 +126,7 @@ namespace flexisip { ...@@ -127,7 +126,7 @@ namespace flexisip {
} }
void disableGlobally() { void disableGlobally() {
ortp_set_log_level(ORTP_LOG_DOMAIN, ORTP_ERROR); bctbx_set_log_level_mask(FLEXISIP_LOG_DOMAIN, BCTBX_LOG_ERROR);
} }
} }
} }
...@@ -65,23 +65,22 @@ inline std::basic_istream<CharT, TraitsT> &operator>>(std::basic_istream<CharT, ...@@ -65,23 +65,22 @@ inline std::basic_istream<CharT, TraitsT> &operator>>(std::basic_istream<CharT,
} //end of namespace log } //end of namespace log
} //end of namespace flexisip } //end of namespace flexisip
#define ORTP_DEBUG_MODE 1 // Flexisip extensively use SLOD #define BCTBX_DEBUG_MODE 1 // Flexisip extensively use SLOD
#ifdef BCTBX_LOG_DOMAIN
#undef BCTBX_LOG_DOMAIN
#endif
#ifndef FLEXISIP_LOG_DOMAIN
#define FLEXISIP_LOG_DOMAIN "flexisip"
#endif
#define BCTBX_LOG_DOMAIN FLEXISIP_LOG_DOMAIN
#include <syslog.h> #include <syslog.h>
#include <ortp/ortp.h> #include "bctoolbox/logging.h"
#include <ostream> #include <ostream>
typedef std::ostream flexisip_record_type; typedef std::ostream flexisip_record_type;
struct pumpstream : public std::ostringstream {
const OrtpLogLevel level;
pumpstream(OrtpLogLevel l) : level(l) {
}
~pumpstream() {
ortp_log(level, "%s", str().c_str());
}
};
#if (__GNUC__ == 4 && __GNUC_MINOR__ < 5) #if (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
template <typename _Tp> inline pumpstream &operator<<(pumpstream &&__os, const _Tp &__x) { template <typename _Tp> inline pumpstream &operator<<(pumpstream &&__os, const _Tp &__x) {
...@@ -89,30 +88,32 @@ template <typename _Tp> inline pumpstream &operator<<(pumpstream &&__os, const _ ...@@ -89,30 +88,32 @@ template <typename _Tp> inline pumpstream &operator<<(pumpstream &&__os, const _
return __os; return __os;
} }
#endif #endif
#define SLOGA_FL(file, line) throw FlexisipException() << " " << file << ":" << line << " " #define SLOGA_FL(file, line) throw FlexisipException() << " " << file << ":" << line << " "
#define SLOG(thelevel) \ #define SLOG(thelevel) BCTBX_SLOG(FLEXISIP_LOG_DOMAIN,thelevel)
if (ortp_log_level_enabled(ORTP_LOG_DOMAIN, (thelevel))) \ #define SLOGD BCTBX_SLOGD(FLEXISIP_LOG_DOMAIN)
pumpstream((thelevel)) #define SLOGI BCTBX_SLOGI(FLEXISIP_LOG_DOMAIN)
#define SLOGD SLOG(ORTP_DEBUG) #define SLOGW BCTBX_SLOGW(FLEXISIP_LOG_DOMAIN)
#define SLOGI SLOG(ORTP_MESSAGE) #define SLOGE BCTBX_SLOGE(FLEXISIP_LOG_DOMAIN)
#define SLOGW SLOG(ORTP_WARNING)
#define SLOGE SLOG(ORTP_ERROR)
/*
#define SLOGA SLOGA_FL(__FILE__,__LINE__)
*/
#define LOGV(thelevel, thefmt, theargs) LOGDV((thefmt), (theargs)) #define LOGV(thelevel, thefmt, theargs) LOGDV((thefmt), (theargs))
#define LOGDV(thefmt, theargs) ortp_logv(ORTP_LOG_DOMAIN, ORTP_DEBUG, (thefmt), (theargs)) #define LOGDV(thefmt, theargs) bctbx_logv(FLEXISIP_LOG_DOMAIN, BCTBX_LOG_DEBUG, (thefmt), (theargs))
#define LOGD ortp_debug
#define LOGI ortp_message #define LOGD bctbx_debug
#define LOGW ortp_warning #define LOGI bctbx_message
#define LOGE ortp_error #define LOGW bctbx_warning
#define LOGA ortp_fatal #define LOGE bctbx_error
#define LOGA bctbx_fatal
#define LOG_SCOPED_THREAD(key, value)
#define LOGDFN(boolFn, streamFn) \ #define LOGDFN(boolFn, streamFn) \
do { \ do { \
if (ortp_log_level_enabled(ORTP_LOG_DOMAIN, (ORTP_DEBUG)) && (boolFn())) { \ if (bctbx_get_log_level_mask(FLEXISIP_LOG_DOMAIN, (BCTBX_LOG_DEBUG)) && (boolFn())) { \
pumpstream pump(ORTP_DEBUG); \ pumpstream pump(BCTBX_LOG_DEBUG); \
(streamFn)(pump); \ (streamFn)(pump); \
} \ } \
} while (0) } while (0)
...@@ -125,7 +126,7 @@ do { ...@@ -125,7 +126,7 @@ do {
*/ */
#define LOGN(args...) \ #define LOGN(args...) \
do { \ do { \
ortp_message(args); \ bctbx_message(args); \
if (sUseSyslog) { \ if (sUseSyslog) { \
syslog(LOG_NOTICE, args); \ syslog(LOG_NOTICE, args); \
} else { \ } else { \
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
using namespace pidf; using namespace pidf;
using namespace flexisip; using namespace flexisip;
void _belle_sip_log(belle_sip_log_level lev, const char *fmt, va_list args) { void _belle_sip_log(const char *domain, BctbxLogLevel lev, const char *fmt, va_list args){
flexisip::log::level level; flexisip::log::level level;
switch (lev) { switch (lev) {
...@@ -77,7 +77,7 @@ PresenceServer::PresenceServer(std::string configFile) throw(FlexisipException) ...@@ -77,7 +77,7 @@ PresenceServer::PresenceServer(std::string configFile) throw(FlexisipException)
, mProvider(belle_sip_stack_create_provider(mStack, NULL)) , mProvider(belle_sip_stack_create_provider(mStack, NULL))
, mIterateThread(nullptr) { , mIterateThread(nullptr) {
belle_sip_set_log_handler(_belle_sip_log); //bctbx_set_log_handler(_belle_sip_log);
belle_sip_set_log_level(BELLE_SIP_LOG_MESSAGE); belle_sip_set_log_level(BELLE_SIP_LOG_MESSAGE);
xercesc::XMLPlatformUtils::Initialize(); xercesc::XMLPlatformUtils::Initialize();
......
...@@ -385,9 +385,9 @@ static string generate_presence_id(void) { ...@@ -385,9 +385,9 @@ static string generate_presence_id(void) {
static char presence_id_valid_start_characters[] = ":_abcdefghijklmnopqrstuvwxyz"; static char presence_id_valid_start_characters[] = ":_abcdefghijklmnopqrstuvwxyz";
char id[7]; char id[7];
int i; int i;
id[0] = presence_id_valid_start_characters[ortp_random() % (sizeof(presence_id_valid_start_characters) - 1)]; id[0] = presence_id_valid_start_characters[belle_sip_random() % (sizeof(presence_id_valid_start_characters) - 1)];
for (i = 1; i < 6; i++) { for (i = 1; i < 6; i++) {
id[i] = presence_id_valid_characters[ortp_random() % (sizeof(presence_id_valid_characters) - 1)]; id[i] = presence_id_valid_characters[belle_sip_random() % (sizeof(presence_id_valid_characters) - 1)];
} }
id[6] = '\0'; id[6] = '\0';
......
bctoolbox @ 8852ed3a
Subproject commit b7dcaa7ec7edd34d5dd37abbe2a5b6a57a9dee53 Subproject commit 8852ed3a237697606f4ffa355edf2a9ed6326640
belle-sip @ 383594e5
Subproject commit 3ff9fc20e71a16f50b58383836fbb47dcb839f26 Subproject commit 383594e5f18090cd67068d84c02b3f8a1371a3e4
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment