1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-03 10:43:58 +02:00

Set GLib log handler

This commit is contained in:
DarthSim 2022-07-29 15:16:24 +06:00
parent cd5c30fa0d
commit a9dda9ca4e
4 changed files with 70 additions and 0 deletions

23
gliblog/gliblog.c Normal file
View File

@ -0,0 +1,23 @@
#include "gliblog.h"
static GLogLevelFlags all_levels =
G_LOG_FLAG_RECURSION |
G_LOG_FLAG_FATAL |
G_LOG_LEVEL_ERROR |
G_LOG_LEVEL_CRITICAL |
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_INFO;
void
log_handler(const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data) {
logGLib((char *)log_domain, log_level, (char *)message);
}
void
glib_log_configure() {
g_log_set_handler (NULL, all_levels, log_handler, NULL);
g_log_set_handler ("VIPS", all_levels, log_handler, NULL);
}

38
gliblog/gliblog.go Normal file
View File

@ -0,0 +1,38 @@
package gliblog
/*
#cgo pkg-config: glib-2.0
#include "gliblog.h"
*/
import "C"
import log "github.com/sirupsen/logrus"
//export logGLib
func logGLib(cdomain *C.char, logLevel C.GLogLevelFlags, cstr *C.char) {
str := C.GoString(cstr)
var domain string
if cdomain != nil {
domain = C.GoString(cdomain)
}
if len(domain) == 0 {
domain = "GLib"
}
entry := log.WithField("source", domain)
switch logLevel {
case C.G_LOG_LEVEL_DEBUG:
entry.Debug(str)
case C.G_LOG_LEVEL_INFO, C.G_LOG_LEVEL_MESSAGE:
entry.Info(str)
case C.G_LOG_LEVEL_WARNING:
entry.Warn(str)
default:
entry.Error(str)
}
}
func Init() {
C.glib_log_configure()
}

6
gliblog/gliblog.h Normal file
View File

@ -0,0 +1,6 @@
#include <glib.h>
void glib_log_configure();
// from Go
void logGLib (char *domain, GLogLevelFlags log_level, char *message);

View File

@ -14,6 +14,7 @@ import (
"github.com/imgproxy/imgproxy/v3/config"
"github.com/imgproxy/imgproxy/v3/errorreport"
"github.com/imgproxy/imgproxy/v3/gliblog"
"github.com/imgproxy/imgproxy/v3/imagedata"
"github.com/imgproxy/imgproxy/v3/logger"
"github.com/imgproxy/imgproxy/v3/memory"
@ -30,6 +31,8 @@ func initialize() error {
return err
}
gliblog.Init()
maxprocs.Set(maxprocs.Logger(log.Debugf))
if err := config.Configure(); err != nil {