mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
merge patch for file logs.
This commit is contained in:
parent
956eb5bcdc
commit
74e2374984
6 changed files with 190 additions and 18 deletions
|
|
@ -3462,6 +3462,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
|
|||
ui_config_uninit(lc);
|
||||
if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
|
||||
lp_config_destroy(lc->config);
|
||||
lc->config = NULL; /* Mark the config as NULL to block further calls */
|
||||
sip_setup_unregister_all();
|
||||
|
||||
linphone_core_free_payload_types();
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@ struct _LinphoneCore;
|
|||
bool_t payload_type_enabled(struct _PayloadType *pt);
|
||||
void payload_type_set_enable(struct _PayloadType *pt,int value);
|
||||
const char *payload_type_get_description(struct _PayloadType *pt);
|
||||
int payload_type_get_bitrate(PayloadType *pt);
|
||||
const char *payload_type_get_mime(PayloadType *pt);
|
||||
int payload_type_get_rate(PayloadType *pt);
|
||||
|
||||
|
||||
struct _LpConfig;
|
||||
|
||||
|
|
|
|||
|
|
@ -185,18 +185,6 @@ bool_t payload_type_enabled(PayloadType *pt) {
|
|||
return (((pt)->flags & PAYLOAD_TYPE_ENABLED)!=0);
|
||||
}
|
||||
|
||||
int payload_type_get_bitrate(PayloadType *pt)
|
||||
{
|
||||
return pt->normal_bitrate;
|
||||
}
|
||||
const char *payload_type_get_mime(PayloadType *pt){
|
||||
return pt->mime_type;
|
||||
}
|
||||
|
||||
int payload_type_get_rate(PayloadType *pt){
|
||||
return pt->clock_rate;
|
||||
}
|
||||
|
||||
/*this function makes a special case for speex/8000.
|
||||
This codec is variable bitrate. The 8kbit/s mode is interesting when having a low upload bandwidth, but its quality
|
||||
is not very good. We 'd better use its 15kbt/s mode when we have enough bandwidth*/
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "linphone.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
|
||||
static GtkWidget *log_window=NULL;
|
||||
static GStaticMutex log_mutex=G_STATIC_MUTEX_INIT;
|
||||
static GList *log_queue=NULL;
|
||||
|
|
@ -28,6 +34,186 @@ typedef struct _LinphoneGtkLog{
|
|||
gchar *msg;
|
||||
}LinphoneGtkLog;
|
||||
|
||||
|
||||
/******
|
||||
* Module to log to a file
|
||||
******/
|
||||
|
||||
/* Marker to insert as a line at the start of every log file */
|
||||
#define LOGFILE_MARKER_START "----<start>----"
|
||||
/* Marker to insert as a line at the end of every log file */
|
||||
#define LOGFILE_MARKER_STOP "----<end>----"
|
||||
/* Number of files to keep in history, log file rotation will be
|
||||
performed. */
|
||||
#define LOGFILE_ROTATION 4
|
||||
/* Pointer to opened log file */
|
||||
static FILE *_logfile = NULL;
|
||||
|
||||
|
||||
/* Called on exit, print out the marker, close the file and avoid to
|
||||
continue logging. */
|
||||
static void linphone_gtk_log_uninit()
|
||||
{
|
||||
if (_logfile != NULL) {
|
||||
fprintf(_logfile, "%s\n", LOGFILE_MARKER_STOP);
|
||||
fclose(_logfile);
|
||||
_logfile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Called when we start logging, find a good place for the log files,
|
||||
perform rotation, insert the start marker and return the pointer to
|
||||
the file that should be used for logging, or NULL on errors or if
|
||||
disabled. */
|
||||
static FILE *linphone_gtk_log_init()
|
||||
{
|
||||
static char _logdir[1024];
|
||||
static char _logfname[1024];
|
||||
static gboolean _log_init = FALSE;
|
||||
const char *dst_fname;
|
||||
|
||||
dst_fname = linphone_gtk_get_ui_config("logfile",NULL);
|
||||
/* For anything to happen, we need a logfile configuration variable,
|
||||
this is our trigger */
|
||||
if (dst_fname) {
|
||||
/* If we haven't initialised yet, arrange for _logdir to contain a
|
||||
directory that has been created and _logfname to contain the
|
||||
path to a file to which we will log */
|
||||
if (!_log_init) {
|
||||
#ifdef WIN32
|
||||
const char *appdata=getenv("LOCALAPPDATA");
|
||||
if (appdata) {
|
||||
snprintf(_logdir, sizeof(_logdir),"%s\\Linphone", appdata);
|
||||
mkdir(_logdir);
|
||||
} else {
|
||||
_logdir[0] = '\0';
|
||||
}
|
||||
#define PATH_SEPARATOR '\\'
|
||||
#else
|
||||
const char *home=getenv("HOME");
|
||||
if (home) {
|
||||
snprintf(_logdir, sizeof(_logdir),"%s/.linphone", home);
|
||||
mkdir(_logdir,S_IRUSR | S_IWUSR | S_IRGRP);
|
||||
} else {
|
||||
_logdir[0] = '\0';
|
||||
}
|
||||
#define PATH_SEPARATOR '/'
|
||||
#endif
|
||||
/* We have a directory, fix the path to the log file in it and
|
||||
open the file so that we will be appending to it. */
|
||||
if (_logdir[0] != '\0') {
|
||||
snprintf(_logfname, sizeof(_logfname), "%s%c%s",
|
||||
_logdir, PATH_SEPARATOR, dst_fname);
|
||||
/* If the constant LOGFILE_ROTATION is greater than zero, then
|
||||
we kick away a simple rotation that will ensure that there
|
||||
are never more than LOGFILE_ROTATION+1 old copies of the
|
||||
log file on the disk. The oldest file is always rotated
|
||||
"away" as expected. Rotated files have the same name as
|
||||
the main log file, though with a number 0..LOGFILE_ROTATION
|
||||
at the end, where the greater the number is, the older the
|
||||
file is. */
|
||||
if (ortp_file_exist(_logfname)==0 && LOGFILE_ROTATION > 0) {
|
||||
int i;
|
||||
char old_fname[1024];
|
||||
char new_fname[1024];
|
||||
|
||||
/* Rotate away existing files. We make sure to remove the
|
||||
old files otherwise rename() would not work properly. We
|
||||
have to loop in reverse here. */
|
||||
for (i=LOGFILE_ROTATION-1;i>=0;i--) {
|
||||
snprintf(old_fname, sizeof(old_fname), "%s%c%s.%d",
|
||||
_logdir, PATH_SEPARATOR, dst_fname, i);
|
||||
snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d",
|
||||
_logdir, PATH_SEPARATOR, dst_fname, i+1);
|
||||
if (ortp_file_exist(old_fname)==0) {
|
||||
if (ortp_file_exist(new_fname)==0)
|
||||
unlink(new_fname);
|
||||
rename(old_fname, new_fname);
|
||||
}
|
||||
}
|
||||
/* Move current log file as the first of the rotation. Make
|
||||
sure to remove the old .0 also, since otherwise rename()
|
||||
would not work as expected. */
|
||||
snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d",
|
||||
_logdir, PATH_SEPARATOR, dst_fname, 0);
|
||||
if (ortp_file_exist(new_fname)==0)
|
||||
unlink(new_fname);
|
||||
rename(_logfname, new_fname);
|
||||
}
|
||||
/* Start a new log file and mark that we have now initialised */
|
||||
_logfile = fopen(_logfname, "w");
|
||||
fprintf(_logfile, "%s\n", LOGFILE_MARKER_START);
|
||||
_log_init = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _logfile;
|
||||
}
|
||||
|
||||
static void linphone_gtk_log_file(OrtpLogLevel lev, const char *msg)
|
||||
{
|
||||
LinphoneCore *lc;
|
||||
time_t now;
|
||||
FILE *outlog;
|
||||
|
||||
lc = linphone_gtk_get_core();
|
||||
/* Nothing to do until the core has initialised */
|
||||
if (lc == NULL)
|
||||
return;
|
||||
|
||||
/* lc->config will turn NULL at exit, close the file to flush and
|
||||
return to stop logging */
|
||||
if (lc->config == NULL) {
|
||||
linphone_gtk_log_uninit();
|
||||
return;
|
||||
}
|
||||
|
||||
outlog = linphone_gtk_log_init();
|
||||
if (outlog != NULL) {
|
||||
/* We have an opened file and we have initialised properly, it's
|
||||
time to write all these log messages. We convert the log level
|
||||
from oRTP into something readable and timestamp each log
|
||||
message. The format of the timestamp can be controlled by
|
||||
logfile_date_format in the GtkUi section of the config file,
|
||||
but it defaults to something compact, but yet readable. */
|
||||
const char *lname="undef";
|
||||
const char *dateformat=linphone_gtk_get_ui_config("logfile_date_format",
|
||||
"%Y%m%d-%H:%M:%S");
|
||||
char date[256];
|
||||
|
||||
/* Convert level constant to text */
|
||||
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:
|
||||
lname="undef";
|
||||
break;
|
||||
}
|
||||
/* Get current time and format it properly */
|
||||
now = time(NULL);
|
||||
strftime(date, sizeof(date), dateformat, localtime(&now));
|
||||
/* Now print out the message to the logfile. We don't flush,
|
||||
maybe we should do to ensure that we have all the messages in
|
||||
case of a crash (which is one of the main reasons we have a
|
||||
log facility in the first place). */
|
||||
fprintf(outlog, "[%s] [%s] %s\n", date, lname, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void linphone_gtk_create_log_window(void){
|
||||
GtkTextBuffer *b;
|
||||
log_window=linphone_gtk_create_window("log");
|
||||
|
|
@ -120,6 +306,7 @@ void linphone_gtk_log_push(OrtpLogLevel lev, const char *fmt, va_list args){
|
|||
lgl->msg=msg;
|
||||
g_static_mutex_lock(&log_mutex);
|
||||
log_queue=g_list_append(log_queue,lgl);
|
||||
linphone_gtk_log_file(lev, msg);
|
||||
g_static_mutex_unlock(&log_mutex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit a11023fbcc2ba355d40d474cc6b863e29a4960fb
|
||||
Subproject commit ab1690f4439e5bbe08c56ca6e20d959e22dc169a
|
||||
2
oRTP
2
oRTP
|
|
@ -1 +1 @@
|
|||
Subproject commit fd65d84014c4cb3c500952c2f4b42dc4630ac37d
|
||||
Subproject commit 36773054c1e9a47029432a2e8540161dad426293
|
||||
Loading…
Add table
Reference in a new issue