|
design_pattern_for_c
V 1.00
|
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>

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_t * | DPTimeLog |
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... | |
For using debug log.
Definition in file dp_debug.h.
| #define DBGFLAG /*if you want to disable all debug information, please comment out it*/ |
Definition at line 57 of file dp_debug.h.
| #define DEBUG_ERRPRINT | ( | ... | ) | DEBUG_ERRPRINT_(__VA_ARGS__, "") |
Definition at line 69 of file dp_debug.h.
| #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.
| #define DEBUG_PRINT | ( | ... | ) |
Definition at line 55 of file dp_debug.h.
| #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.
| #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.
| #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 struct dp_timelog_t dp_timelog_t |
Definition at line 20 of file dp_debug.h.
| typedef struct dp_timelog_t * DPTimeLog |
Definition at line 20 of file dp_debug.h.
| void dp_timelog_exit | ( | DPTimeLog | handle | ) |
Exit stored log, and show stored log.
| [in] | handle | handle returned from timelog_init |
Definition at line 162 of file dp_timelog.c.

| DPTimeLog dp_timelog_init | ( | const char * | delimiter, |
| size_t | maxloglen, | ||
| unsigned long | maxstoresize, | ||
| int | is_threadsafe | ||
| ) |
Init store log.
| [in] | delimiter | delimiter string if you want, default:" " |
| [in] | maxloglen | Max length of logs |
| [in] | maxstoresize | Storaged log size. If 0, always show log |
| [in] | is_threadsafe | threadsafe or not |
| !NULL | handle pointer to use other method |
| NULL | error |
Definition at line 85 of file dp_timelog.c.
| int dp_timelog_print | ( | DPTimeLog | handle, |
| const char * | format, | ||
| ... | |||
| ) |
Store log.
| [in] | handle | handle returned from timelog_init |
| [in] | format | log format as printf |
| 0<=val | success |
| other | failed (same as prinf) |
Definition at line 139 of file dp_timelog.c.

| 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.