core/log: Improve logging
- Stop using GDateTime formatting as that's super slow! - Log the thread id as wel Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/858>
This commit is contained in:
committed by
Marge Bot
parent
509165286e
commit
6c2bc5be46
+31
-9
@@ -16,6 +16,15 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
# define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/syscall.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gcal-debug.h"
|
#include "gcal-debug.h"
|
||||||
#include "gcal-log.h"
|
#include "gcal-log.h"
|
||||||
|
|
||||||
@@ -34,6 +43,16 @@ static const gchar* ignored_domains[] =
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline gint
|
||||||
|
get_thread_id (void)
|
||||||
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
return (gint) syscall (SYS_gettid);
|
||||||
|
#else
|
||||||
|
return GPOINTER_TO_INT (g_thread_self ());
|
||||||
|
#endif /* __linux__ */
|
||||||
|
}
|
||||||
|
|
||||||
static const gchar *
|
static const gchar *
|
||||||
log_level_str (GLogLevelFlags log_level)
|
log_level_str (GLogLevelFlags log_level)
|
||||||
{
|
{
|
||||||
@@ -58,11 +77,12 @@ gcal_log_handler (const gchar *domain,
|
|||||||
const gchar *message,
|
const gchar *message,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
g_autoptr (GDateTime) now = NULL;
|
gint64 now;
|
||||||
g_autofree gchar *buffer = NULL;
|
struct tm tt;
|
||||||
g_autofree gchar *ftime = NULL;
|
time_t t;
|
||||||
const gchar *level;
|
const gchar *level;
|
||||||
gint microsecond;
|
gchar ftime[32];
|
||||||
|
gchar *buffer;
|
||||||
|
|
||||||
/* Skip ignored log domains */
|
/* Skip ignored log domains */
|
||||||
if (domain && g_strv_contains (ignored_domains, domain))
|
if (domain && g_strv_contains (ignored_domains, domain))
|
||||||
@@ -95,13 +115,15 @@ gcal_log_handler (const gchar *domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
level = log_level_str (log_level);
|
level = log_level_str (log_level);
|
||||||
now = g_date_time_new_now_local ();
|
now = g_get_real_time ();
|
||||||
ftime = g_date_time_format (now, "%H:%M:%S");
|
t = now / G_USEC_PER_SEC;
|
||||||
microsecond = g_date_time_get_microsecond (now);
|
tt = *localtime (&t);
|
||||||
buffer = g_strdup_printf ("%s.%04d\t%28s: %s: %s\n",
|
strftime (ftime, sizeof (ftime), "%H:%M:%S", &tt);
|
||||||
|
buffer = g_strdup_printf ("%s.%04d\t%30s[%5d]: %s: %s\n",
|
||||||
ftime,
|
ftime,
|
||||||
microsecond,
|
(gint)((now % G_USEC_PER_SEC) / 100L),
|
||||||
domain,
|
domain,
|
||||||
|
get_thread_id (),
|
||||||
level,
|
level,
|
||||||
message);
|
message);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user