design_pattern_for_c  V 1.00
dp_debug.h File Reference

For using debug log. More...

#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
Include dependency graph for dp_debug.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUG_PRINT(...)
 
#define DBGFLAG   /*if you want to disable all debug information, please comment out it*/
 
#define DPDEBUG_INIT   timelog_g=dp_timelog_init(",", 2048, 8192, 0); dp_timelog_print(timelog_g,"init\n");
 If you want to show deail log, please set DPDEBUG_INIT or DPDEBUG_INIT_THREADSAFE at start, and set DPDEBUG_EXIT at end. More...
 
#define DPDEBUG_INIT_THREADSAFE   timelog_g=dp_timelog_init(",", 2048, 1, 1); dp_timelog_print(timelog_g,"init\n");
 If you want to show deail log, please set DPDEBUG_INIT or DPDEBUG_INIT_THREADSAFE at start, and set DPDEBUG_EXIT at end. More...
 
#define DEBUG_ERRPRINT(...)   DEBUG_ERRPRINT_(__VA_ARGS__, "")
 
#define DEBUG_ERRPRINT_(fmt, ...)   dp_timelog_print(timelog_g, "[%s(%s:%d)thread:%x]: "fmt"%s", __FUNCTION__,__FILE__,__LINE__,(unsigned int)pthread_self(), __VA_ARGS__)
 
#define DPDEBUG_EXIT   dp_timelog_print(timelog_g,"exit\n");dp_timelog_exit(timelog_g);timelog_g=NULL;
 If you want to show deail log, please set DPDEBUG_INIT or DPDEBUG_INIT_THREADSAFE at start, and set DPDEBUG_EXIT at end. More...
 

Typedefs

typedef struct dp_timelog_t dp_timelog_t
 
typedef struct dp_timelog_tDPTimeLog
 

Functions

DPTimeLog dp_timelog_init (const char *delimiter, size_t maxloglen, unsigned long maxstoresize, int is_threadsafe)
 Init store log. More...
 
int dp_timelog_print (DPTimeLog handle, const char *format,...)
 Store log. More...
 
void dp_timelog_exit (DPTimeLog handle)
 Exit stored log, and show stored log. More...
 

Variables

DPTimeLog timelog_g
 global timelog handle to show debug log More...
 

Detailed Description

For using debug log.

Definition in file dp_debug.h.

Macro Definition Documentation

◆ DBGFLAG

#define DBGFLAG   /*if you want to disable all debug information, please comment out it*/

Definition at line 57 of file dp_debug.h.

◆ DEBUG_ERRPRINT

#define DEBUG_ERRPRINT (   ...)    DEBUG_ERRPRINT_(__VA_ARGS__, "")

Definition at line 69 of file dp_debug.h.

◆ DEBUG_ERRPRINT_

#define DEBUG_ERRPRINT_ (   fmt,
  ... 
)    dp_timelog_print(timelog_g, "[%s(%s:%d)thread:%x]: "fmt"%s", __FUNCTION__,__FILE__,__LINE__,(unsigned int)pthread_self(), __VA_ARGS__)

Definition at line 70 of file dp_debug.h.

◆ DEBUG_PRINT

#define DEBUG_PRINT (   ...)

Definition at line 55 of file dp_debug.h.

◆ DPDEBUG_EXIT

#define DPDEBUG_EXIT   dp_timelog_print(timelog_g,"exit\n");dp_timelog_exit(timelog_g);timelog_g=NULL;

If you want to show deail log, please set DPDEBUG_INIT or DPDEBUG_INIT_THREADSAFE at start, and set DPDEBUG_EXIT at end.

Definition at line 73 of file dp_debug.h.

◆ DPDEBUG_INIT

#define DPDEBUG_INIT   timelog_g=dp_timelog_init(",", 2048, 8192, 0); dp_timelog_print(timelog_g,"init\n");

If you want to show deail log, please set DPDEBUG_INIT or DPDEBUG_INIT_THREADSAFE at start, and set DPDEBUG_EXIT at end.

Definition at line 65 of file dp_debug.h.

◆ DPDEBUG_INIT_THREADSAFE

#define DPDEBUG_INIT_THREADSAFE   timelog_g=dp_timelog_init(",", 2048, 1, 1); dp_timelog_print(timelog_g,"init\n");

If you want to show deail log, please set DPDEBUG_INIT or DPDEBUG_INIT_THREADSAFE at start, and set DPDEBUG_EXIT at end.

Definition at line 67 of file dp_debug.h.

Typedef Documentation

◆ dp_timelog_t

typedef struct dp_timelog_t dp_timelog_t

Definition at line 20 of file dp_debug.h.

◆ DPTimeLog

typedef struct dp_timelog_t * DPTimeLog

Definition at line 20 of file dp_debug.h.

Function Documentation

◆ dp_timelog_exit()

void dp_timelog_exit ( DPTimeLog  handle)

Exit stored log, and show stored log.

Parameters
[in]handlehandle returned from timelog_init
Returns
none

Definition at line 162 of file dp_timelog.c.

Here is the call graph for this function:

◆ dp_timelog_init()

DPTimeLog dp_timelog_init ( const char *  delimiter,
size_t  maxloglen,
unsigned long  maxstoresize,
int  is_threadsafe 
)

Init store log.

Parameters
[in]delimiterdelimiter string if you want, default:" "
[in]maxloglenMax length of logs
[in]maxstoresizeStoraged log size. If 0, always show log
[in]is_threadsafethreadsafe or not
Return values
!NULLhandle pointer to use other method
NULLerror

Definition at line 85 of file dp_timelog.c.

◆ dp_timelog_print()

int dp_timelog_print ( DPTimeLog  handle,
const char *  format,
  ... 
)

Store log.

Parameters
[in]handlehandle returned from timelog_init
[in]formatlog format as printf
Return values
0<=valsuccess
otherfailed (same as prinf)

Definition at line 139 of file dp_timelog.c.

Here is the call graph for this function:

Variable Documentation

◆ timelog_g

DPTimeLog timelog_g

global timelog handle to show debug log

global timelog handle to show debug log

Definition at line 14 of file dp_timelog.c.