From: <svn...@op...> - 2009-04-02 14:35:37
|
Author: bellmich Date: Thu Apr 2 16:35:33 2009 New Revision: 1024 URL: http://libsyncml.opensync.org/changeset/1024 Log: fixed ticket #222 Modified: trunk/libsyncml/sml_support.c Modified: trunk/libsyncml/sml_support.c ============================================================================== --- trunk/libsyncml/sml_support.c Mon Mar 30 13:05:37 2009 (r1023) +++ trunk/libsyncml/sml_support.c Thu Apr 2 16:35:33 2009 (r1024) @@ -130,9 +130,21 @@ current_tabs = g_private_new (NULL); else tabs = GPOINTER_TO_INT(g_private_get(current_tabs)); - - unsigned long int id = (unsigned long int)pthread_self(); - pid_t pid = getpid(); + + unsigned long int id; + pid_t pid; + const char *endline; +#ifdef _WIN32 + if (!thread_id) + thread_id = g_private_new (NULL); + id = GPOINTER_TO_INT(thread_id); + pid = _getpid(); + endline = "\r\n"; +#else + id = (unsigned long int)pthread_self(); + pid = getpid(); + endline = "\n"; +#endif char *logfile = g_strdup_printf("%s/Thread%lu-%d.log", trace, id, pid); // create message @@ -173,23 +185,23 @@ char *logmessage = NULL; switch (type) { case TRACE_ENTRY: - logmessage = g_strdup_printf("[%li.%06li]\t%s>>>>>>> %s\n", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer); + logmessage = g_strdup_printf("[%li.%06li]\t%s>>>>>>> %s%s", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer, endline); tabs++; break; case TRACE_INTERNAL: - logmessage = g_strdup_printf("[%li.%06li]\t%s%s\n", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer); + logmessage = g_strdup_printf("[%li.%06li]\t%s%s%s", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer, endline); break; case TRACE_ERROR: - logmessage = g_strdup_printf("[%li.%06li]\t%sERROR: %s\n", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer); + logmessage = g_strdup_printf("[%li.%06li]\t%sERROR: %s%s", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer, endline); break; case TRACE_EXIT: - logmessage = g_strdup_printf("[%li.%06li]%s<<<<<<< %s\n", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer); + logmessage = g_strdup_printf("[%li.%06li]%s<<<<<<< %s%s", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer, endline); tabs--; if (tabs < 0) tabs = 0; break; case TRACE_EXIT_ERROR: - logmessage = g_strdup_printf("[%li.%06li]%s<--- ERROR --- %s\n", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer); + logmessage = g_strdup_printf("[%li.%06li]%s<--- ERROR --- %s%s", curtime.tv_sec, curtime.tv_usec, tabstr->str, buffer, endline); tabs--; if (tabs < 0) tabs = 0; @@ -204,7 +216,7 @@ GError *error = NULL; GIOChannel *chan = g_io_channel_new_file(logfile, "a", &error); if (!chan) { - printf("unable to open %s for writing: %s\n", logfile, error->message); + printf("unable to open %s for writing: %s%s", logfile, error->message, endline); smlSafeCFree(&logfile); smlSafeCFree(&logmessage); return; @@ -213,7 +225,7 @@ gsize writen; g_io_channel_set_encoding(chan, NULL, NULL); if (g_io_channel_write_chars(chan, logmessage, strlen(logmessage), &writen, NULL) != G_IO_STATUS_NORMAL) { - printf("unable to write trace to %s\n", logfile); + printf("unable to write trace to %s%s", logfile, endline); } else g_io_channel_flush(chan, NULL); |