00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00047 #define _GNU_SOURCE
00048 #include <stdio.h>
00049 #include <stdarg.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #include <unistd.h>
00053
00054 #include "debug.h"
00055 #ifdef TOFILE_DEBUG
00056
00060 int debug_file_fd = -1;
00061 #endif
00062
00067 void
00068 _EasyDbusDebug (const char *file,
00069 const char *function, int line, const char *fmt, ...)
00070 {
00071 char *ptr;
00072 char *pptr;
00073 va_list ap;
00074
00075 va_start (ap, fmt);
00076 vasprintf (&ptr, fmt, ap);
00077 va_end (ap);
00078
00079 pptr = ptr + strlen (ptr) - 1;
00080 if (*pptr == '\n')
00081 *pptr = ' ';
00082
00083 #ifdef TOFILE_DEBUG
00084 char buffer[1024];
00085
00086 snprintf (buffer, 1024, "[%s@%s:%d] %s\n", file, function, line, ptr);
00087 write (debug_file_fd, buffer, strlen (buffer));
00088 #else
00089 fprintf (stderr, "[%s@%s:%d] %s\n", file, function, line, ptr);
00090 fflush (stderr);
00091 #endif
00092 free (ptr);
00093 }
00094
00095 #ifdef TOFILE_DEBUG
00096 # include <sys/types.h>
00097 # include <sys/stat.h>
00098 # include <fcntl.h>
00099
00110 int
00111 easydbus_init_logger (char *debug_file)
00112 {
00113 if (debug_file == NULL)
00114 return -1;
00115
00116 debug_file_fd = open (debug_file, O_WRONLY | O_APPEND | O_CREAT,
00117 S_IRGRP | S_IRWXU | S_IROTH);
00118
00119 if (debug_file_fd == -1)
00120 return -1;
00121
00122 return 0;
00123 }
00124
00131 void
00132 easydbus_deinit_logger (void)
00133 {
00134 close (debug_file_fd);
00135 }
00136
00137 #endif
00138
00139