53 static int sphinx_debug_level;
57 int prev = sphinx_debug_level;
58 sphinx_debug_level = level;
64 return sphinx_debug_level;
80 #if defined(HAVE_PTHREAD_H)
82 static pthread_key_t logfp_index;
83 static pthread_once_t logfp_index_once = PTHREAD_ONCE_INIT;
86 logfp_index_alloc(
void)
88 pthread_key_create(&logfp_index, NULL);
96 pthread_once(&logfp_index_once, logfp_index_alloc);
97 logfp = (FILE *)pthread_getspecific(logfp_index);
101 else if (logfp == (FILE*) -1)
108 internal_set_logfp(FILE *fh)
113 pthread_setspecific(logfp_index, (
void *)fh);
116 #elif defined(_WIN32) || defined(__CYGWIN__)
118 static DWORD logfp_index;
119 static LONG logfp_index_once = 0;
122 logfp_index_alloc(
void)
124 logfp_index = TlsAlloc();
132 if (InterlockedExchange(&logfp_index_once, 1) == 0)
134 logfp = (FILE *)TlsGetValue(logfp_index);
138 else if (logfp == (FILE*) -1)
145 internal_set_logfp(FILE *fh)
150 TlsSetValue(logfp_index, (
void *)fh);
161 else if (logfp == (FILE*) -1)
168 internal_set_logfp(FILE *fh)
184 internal_set_logfp(newfp);
194 if ((newfp = fopen(file,
"a")) == NULL)
197 internal_set_logfp(newfp);
198 if (oldfp != NULL && oldfp != stdout && oldfp != stderr)
205 _E__pr_info_header_wofn(
char const *msg)
213 fprintf(logfp,
"%s:\t", msg);
218 _E__pr_header(
char const *f,
long ln,
char const *msg)
226 fname = strrchr(f,
'\\');
228 fname = strrchr(f,
'/');
229 fprintf(logfp,
"%s: \"%s\", line %ld: ", msg, fname == NULL ? f : fname + 1, ln);
234 _E__pr_info_header(
char const *f,
long ln,
char const *msg)
242 fname = strrchr(f,
'\\');
244 fname = strrchr(f,
'/');
246 fprintf(logfp,
"%s: %s(%ld): ", msg, fname == NULL ? f : fname + 1, ln);
251 _E__pr_warn(
char const *fmt, ...)
260 vfprintf(logfp, fmt, pvar);
267 _E__pr_info(
char const *fmt, ...)
276 vfprintf(logfp, fmt, pvar);
283 _E__die_error(
char const *fmt, ...)
291 vfprintf(logfp, fmt, pvar);
296 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
304 _E__fatal_sys_error(
char const *fmt, ...)
308 int local_errno = errno;
313 vfprintf(logfp, fmt, pvar);
316 fprintf(logfp,
": %s\n", strerror(local_errno));
321 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
330 _E__sys_error(
char const *fmt, ...)
334 int local_errno = errno;
341 vfprintf(logfp, fmt, pvar);
344 fprintf(logfp,
": %s\n", strerror(local_errno));
349 _E__abort_error(
char const *fmt, ...)
357 vfprintf(logfp, fmt, pvar);
362 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
364 #elif defined(_WIN32_WCE)
FILE * err_set_logfp(FILE *newfp)
Direct all logging to a given filehandle.
int err_set_debug_level(int level)
Set debugging verbosity level.
Implementation of logging routines.
int err_set_logfile(char const *file)
Append all log messages to a given file.
FILE * err_get_logfp(void)
Get the current logging filehandle.
int err_get_debug_level(void)
Get debugging verbosity level.