Commit 00401563 authored by Ghislain MARY's avatar Ghislain MARY

Move logging to separate header and source files.

parent fe897fd4
......@@ -2,7 +2,7 @@
ortp_includedir=$(includedir)/ortp
ortp_include_HEADERS=str_utils.h rtpsession.h rtp.h port.h \
ortp_include_HEADERS=str_utils.h rtpsession.h rtp.h port.h logging.h \
ortp.h telephonyevents.h sessionset.h payloadtype.h rtpsignaltable.h \
rtcp.h \
event.h stun.h stun_udp.h ortp_srtp.h zrtp.h \
......
/*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file logging.h
* \brief Logging API.
*
**/
#ifndef ORTP_LOGGING_H
#define ORTP_LOGGING_H
#include <ortp/port.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef enum {
ORTP_DEBUG=1,
ORTP_MESSAGE=1<<1,
ORTP_WARNING=1<<2,
ORTP_ERROR=1<<3,
ORTP_FATAL=1<<4,
ORTP_TRACE=1<<5,
ORTP_LOGLEV_END=1<<6
} OrtpLogLevel;
typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
void ortp_set_log_file(FILE *file);
void ortp_set_log_handler(OrtpLogFunc func);
VAR_DECLSPEC OrtpLogFunc ortp_logv_out;
extern unsigned int __ortp_log_mask;
#define ortp_log_level_enabled(level) (__ortp_log_mask & (level))
#if !defined(WIN32) && !defined(_WIN32_WCE)
#define ortp_logv(level,fmt,args) \
{\
if (ortp_logv_out!=NULL && ortp_log_level_enabled(level)) \
ortp_logv_out(level,fmt,args);\
if ((level)==ORTP_FATAL) abort();\
}while(0)
#else
void ortp_logv(int level, const char *fmt, va_list args);
#endif
void ortp_set_log_level_mask(int levelmask);
#ifdef __GNUC__
#define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
#else
#define CHECK_FORMAT_ARGS(m,n)
#endif
#ifdef ORTP_DEBUG_MODE
static inline void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_DEBUG, fmt, args);
va_end (args);
}
#else
#define ortp_debug(...)
#endif
#ifdef ORTP_NOMESSAGE_MODE
#define ortp_log(...)
#define ortp_message(...)
#define ortp_warning(...)
#else
static inline void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
va_list args;
va_start (args, fmt);
ortp_logv(lev, fmt, args);
va_end (args);
}
static inline void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_MESSAGE, fmt, args);
va_end (args);
}
static inline void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_WARNING, fmt, args);
va_end (args);
}
#endif
static inline void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_ERROR, fmt, args);
va_end (args);
}
static inline void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_FATAL, fmt, args);
va_end (args);
}
#ifdef __cplusplus
}
#endif
#endif
......@@ -64,6 +64,7 @@
#ifndef ORTP_H
#define ORTP_H
#include "ortp/logging.h"
#include "ortp/rtpsession.h"
#include "ortp/sessionset.h"
......@@ -77,116 +78,6 @@ void ortp_init(void);
void ortp_scheduler_init(void);
void ortp_exit(void);
/***************/
/* logging api */
/***************/
typedef enum {
ORTP_DEBUG=1,
ORTP_MESSAGE=1<<1,
ORTP_WARNING=1<<2,
ORTP_ERROR=1<<3,
ORTP_FATAL=1<<4,
ORTP_TRACE=1<<5,
ORTP_LOGLEV_END=1<<6
} OrtpLogLevel;
typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
void ortp_set_log_file(FILE *file);
void ortp_set_log_handler(OrtpLogFunc func);
VAR_DECLSPEC OrtpLogFunc ortp_logv_out;
extern unsigned int __ortp_log_mask;
#define ortp_log_level_enabled(level) (__ortp_log_mask & (level))
#if !defined(WIN32) && !defined(_WIN32_WCE)
#define ortp_logv(level,fmt,args) \
{\
if (ortp_logv_out!=NULL && ortp_log_level_enabled(level)) \
ortp_logv_out(level,fmt,args);\
if ((level)==ORTP_FATAL) abort();\
}while(0)
#else
void ortp_logv(int level, const char *fmt, va_list args);
#endif
void ortp_set_log_level_mask(int levelmask);
#ifdef __GNUC__
#define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
#else
#define CHECK_FORMAT_ARGS(m,n)
#endif
#ifdef ORTP_DEBUG_MODE
static inline void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_DEBUG, fmt, args);
va_end (args);
}
#else
#define ortp_debug(...)
#endif
#ifdef ORTP_NOMESSAGE_MODE
#define ortp_log(...)
#define ortp_message(...)
#define ortp_warning(...)
#else
static inline void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
va_list args;
va_start (args, fmt);
ortp_logv(lev, fmt, args);
va_end (args);
}
static inline void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_MESSAGE, fmt, args);
va_end (args);
}
static inline void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_WARNING, fmt, args);
va_end (args);
}
#endif
static inline void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_ERROR, fmt, args);
va_end (args);
}
static inline void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_FATAL, fmt, args);
va_end (args);
}
/****************/
/*statistics api*/
/****************/
......
......@@ -10,6 +10,7 @@ lib_LTLIBRARIES = libortp.la
libortp_la_SOURCES= str_utils.c \
port.c \
logging.c logging.h \
rtpparse.c \
rtpsession.c \
rtpsession_inet.c \
......
/*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ortp/logging.h"
static FILE *__log_file=0;
/**
*@param file a FILE pointer where to output the ortp logs.
*
**/
void ortp_set_log_file(FILE *file)
{
__log_file=file;
}
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args);
OrtpLogFunc ortp_logv_out=__ortp_logv_out;
/**
*@param func: your logging function, compatible with the OrtpLogFunc prototype.
*
**/
void ortp_set_log_handler(OrtpLogFunc func){
ortp_logv_out=func;
}
unsigned int __ortp_log_mask=ORTP_WARNING|ORTP_ERROR|ORTP_FATAL;
/**
* @ param levelmask a mask of ORTP_DEBUG, ORTP_MESSAGE, ORTP_WARNING, ORTP_ERROR
* ORTP_FATAL .
**/
void ortp_set_log_level_mask(int levelmask){
__ortp_log_mask=levelmask;
}
char * ortp_strdup_vprintf(const char *fmt, va_list ap)
{
/* Guess we need no more than 100 bytes. */
int n, size = 200;
char *p,*np;
#ifndef WIN32
va_list cap;/*copy of our argument list: a va_list cannot be re-used (SIGSEGV on linux 64 bits)*/
#endif
if ((p = (char *) ortp_malloc (size)) == NULL)
return NULL;
while (1)
{
/* Try to print in the allocated space. */
#ifndef WIN32
va_copy(cap,ap);
n = vsnprintf (p, size, fmt, cap);
va_end(cap);
#else
/*this works on 32 bits, luckily*/
n = vsnprintf (p, size, fmt, ap);
#endif
/* If that worked, return the string. */
if (n > -1 && n < size)
return p;
//printf("Reallocing space.\n");
/* Else try again with more space. */
if (n > -1) /* glibc 2.1 */
size = n + 1; /* precisely what is needed */
else /* glibc 2.0 */
size *= 2; /* twice the old size */
if ((np = (char *) ortp_realloc (p, size)) == NULL)
{
free(p);
return NULL;
}
else
{
p = np;
}
}
}
char *ortp_strdup_printf(const char *fmt,...){
char *ret;
va_list args;
va_start (args, fmt);
ret=ortp_strdup_vprintf(fmt, args);
va_end (args);
return ret;
}
#if defined(WIN32) || defined(_WIN32_WCE)
#define ENDLINE "\r\n"
#else
#define ENDLINE "\n"
#endif
#if defined(WIN32) || defined(_WIN32_WCE)
void ortp_logv(int level, const char *fmt, va_list args)
{
if (ortp_logv_out!=NULL && ortp_log_level_enabled(level))
ortp_logv_out(level,fmt,args);
#if !defined(_WIN32_WCE)
if ((level)==ORTP_FATAL) abort();
#endif
}
#endif
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){
const char *lname="undef";
char *msg;
if (__log_file==NULL) __log_file=stderr;
switch(lev){
case ORTP_DEBUG:
lname="debug";
break;
case ORTP_MESSAGE:
lname="message";
break;
case ORTP_WARNING:
lname="warning";
break;
case ORTP_ERROR:
lname="error";
break;
case ORTP_FATAL:
lname="fatal";
break;
default:
ortp_fatal("Bad level !");
}
msg=ortp_strdup_vprintf(fmt,args);
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
OutputDebugString(msg);
OutputDebugString("\r\n");
#endif
fprintf(__log_file,"ortp-%s-%s" ENDLINE,lname,msg);
fflush(__log_file);
ortp_free(msg);
}
......@@ -153,141 +153,6 @@ RtpScheduler * ortp_get_scheduler()
}
static FILE *__log_file=0;
/**
*@param file a FILE pointer where to output the ortp logs.
*
**/
void ortp_set_log_file(FILE *file)
{
__log_file=file;
}
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args);
OrtpLogFunc ortp_logv_out=__ortp_logv_out;
/**
*@param func: your logging function, compatible with the OrtpLogFunc prototype.
*
**/
void ortp_set_log_handler(OrtpLogFunc func){
ortp_logv_out=func;
}
unsigned int __ortp_log_mask=ORTP_WARNING|ORTP_ERROR|ORTP_FATAL;
/**
* @ param levelmask a mask of ORTP_DEBUG, ORTP_MESSAGE, ORTP_WARNING, ORTP_ERROR
* ORTP_FATAL .
**/
void ortp_set_log_level_mask(int levelmask){
__ortp_log_mask=levelmask;
}
char * ortp_strdup_vprintf(const char *fmt, va_list ap)
{
/* Guess we need no more than 100 bytes. */
int n, size = 200;
char *p,*np;
#ifndef WIN32
va_list cap;/*copy of our argument list: a va_list cannot be re-used (SIGSEGV on linux 64 bits)*/
#endif
if ((p = (char *) ortp_malloc (size)) == NULL)
return NULL;
while (1)
{
/* Try to print in the allocated space. */
#ifndef WIN32
va_copy(cap,ap);
n = vsnprintf (p, size, fmt, cap);
va_end(cap);
#else
/*this works on 32 bits, luckily*/
n = vsnprintf (p, size, fmt, ap);
#endif
/* If that worked, return the string. */
if (n > -1 && n < size)
return p;
//printf("Reallocing space.\n");
/* Else try again with more space. */
if (n > -1) /* glibc 2.1 */
size = n + 1; /* precisely what is needed */
else /* glibc 2.0 */
size *= 2; /* twice the old size */
if ((np = (char *) ortp_realloc (p, size)) == NULL)
{
free(p);
return NULL;
}
else
{
p = np;
}
}
}
char *ortp_strdup_printf(const char *fmt,...){
char *ret;
va_list args;
va_start (args, fmt);
ret=ortp_strdup_vprintf(fmt, args);
va_end (args);
return ret;
}
#if defined(WIN32) || defined(_WIN32_WCE)
#define ENDLINE "\r\n"
#else
#define ENDLINE "\n"
#endif
#if defined(WIN32) || defined(_WIN32_WCE)
void ortp_logv(int level, const char *fmt, va_list args)
{
if (ortp_logv_out!=NULL && ortp_log_level_enabled(level))
ortp_logv_out(level,fmt,args);
#if !defined(_WIN32_WCE)
if ((level)==ORTP_FATAL) abort();
#endif
}
#endif
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){
const char *lname="undef";
char *msg;
if (__log_file==NULL) __log_file=stderr;
switch(lev){
case ORTP_DEBUG:
lname="debug";
break;
case ORTP_MESSAGE:
lname="message";
break;
case ORTP_WARNING:
lname="warning";
break;
case ORTP_ERROR:
lname="error";
break;
case ORTP_FATAL:
lname="fatal";
break;
default:
ortp_fatal("Bad level !");
}
msg=ortp_strdup_vprintf(fmt,args);
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
OutputDebugString(msg);
OutputDebugString("\r\n");
#endif
fprintf(__log_file,"ortp-%s-%s" ENDLINE,lname,msg);
fflush(__log_file);
ortp_free(msg);
}
/**
* Display global statistics (cumulative for all RtpSession)
**/
......
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