z-univ.h z-oclcui.h zes-expi.h zes-exps.h zes-order.h zes-pquery.h \
zes-psched.h zes-admin.h zes-pset.h zes-update.h zes-update0.h \
zoom.h z-charneg.h charneg.h soap.h srw.h zgdu.h matchstr.h json.h \
- file_glob.h dirent.h
+ file_glob.h dirent.h thread_id.h
EXTRA_DIST = yaz-version.h.in
#define YLOG_LOG 0x00000008
/** \brief log level: append system error message */
#define YLOG_ERRNO 0x00000010
+/** \brief log level: append thread Id */
+#define YLOG_TID 0x00000020
/** \brief log level: application */
#define YLOG_APP 0x00000040
/** \brief log level: malloc debug */
--- /dev/null
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data.
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Index Data nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file mutex.h
+ * \brief Header for Mutex functions
+ */
+#ifndef YAZ_THREAD_ID_H
+#define YAZ_THREAD_ID_H
+
+#include <stddef.h>
+#include <yaz/yconfig.h>
+
+YAZ_BEGIN_CDECL
+
+/** \brief format current thread as printable C-string
+ \param buf buffer for string
+ \param buf_max maximum number of bytes (including trailing \0)
+ */
+
+YAZ_EXPORT
+void yaz_thread_id_cstr(char *buf, size_t buf_max);
+
+YAZ_END_CDECL
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
copy_types.c match_glob.c poll.c daemon.c \
iconv_encode_marc8.c iconv_encode_iso_8859_1.c iconv_encode_wchar.c \
iconv_decode_marc8.c iconv_decode_iso5426.c iconv_decode_danmarc.c sc.c \
- json.c xml_include.c file_glob.c dirent.c mutex.c
+ json.c xml_include.c file_glob.c dirent.c mutex.c thread_id.c
libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO)
#include <errno.h>
#include <time.h>
#include <yaz/errno.h>
+#include <yaz/thread_id.h>
#include <yaz/log.h>
#include <yaz/snprintf.h>
#include <yaz/xmalloc.h>
static char l_old_default_format[] = "%H:%M:%S-%d/%m";
static char l_new_default_format[] = "%Y%m%d-%H%M%S";
#define TIMEFORMAT_LEN 50
+#define TID_LEN 30
static char l_custom_format[TIMEFORMAT_LEN] = "";
static char *l_actual_format = l_old_default_format;
{ YLOG_LOG, "log" },
{ YLOG_ERRNO, ""},
{ YLOG_MALLOC, "malloc"},
- { YLOG_APP, "app" },
+ { YLOG_TID, "tid" },
+ { YLOG_APP, "app" },
{ YLOG_NOTIME, "notime" },
{ YLOG_APP2, "app2" },
{ YLOG_APP3, "app3" },
if (file)
{
char tbuf[TIMEFORMAT_LEN];
+ char tid[TID_LEN];
char flags[1024];
int i;
}
if (tbuf[0])
strcat(tbuf, " ");
- fprintf(file, "%s%s%s %s%s\n", tbuf, l_prefix, flags, l_prefix2,
+ tid[0] = '\0';
+
+ if (l_level & YLOG_TID)
+ {
+ yaz_thread_id_cstr(tid, sizeof(tid)-1);
+ if (tid[0])
+ strcat(tid, " ");
+ }
+
+ fprintf(file, "%s%s%s%s %s%s\n", tbuf, l_prefix, tid, flags, l_prefix2,
log_message);
if (l_level & YLOG_FLUSH)
fflush(file);
--- /dev/null
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+/**
+ * \file thraedid.c
+ * \brief Returns printable thread ID
+ *
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#if YAZ_POSIX_THREADS
+#include <pthread.h>
+#endif
+
+#include <yaz/thread_id.h>
+
+void yaz_thread_id_cstr(char *buf, size_t buf_max)
+{
+#ifdef WIN32
+ *buf = '\0';
+#elif YAZ_POSIX_THREADS
+ pthread_t t = pthread_self();
+ size_t i;
+ *buf = '\0';
+ for (i = 0; i < sizeof(t); i++)
+ {
+ if (strlen(buf) >= buf_max-2)
+ break;
+ sprintf(buf + strlen(buf), "%02x", ((const unsigned char *) &t)[i]);
+ }
+#else
+ *buf = '\0';
+#endif
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+