mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-09 11:42:48 +02:00
Set GLib log handler
This commit is contained in:
23
gliblog/gliblog.c
Normal file
23
gliblog/gliblog.c
Normal 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
38
gliblog/gliblog.go
Normal 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
6
gliblog/gliblog.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
void glib_log_configure();
|
||||||
|
|
||||||
|
// from Go
|
||||||
|
void logGLib (char *domain, GLogLevelFlags log_level, char *message);
|
3
main.go
3
main.go
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/imgproxy/imgproxy/v3/config"
|
"github.com/imgproxy/imgproxy/v3/config"
|
||||||
"github.com/imgproxy/imgproxy/v3/errorreport"
|
"github.com/imgproxy/imgproxy/v3/errorreport"
|
||||||
|
"github.com/imgproxy/imgproxy/v3/gliblog"
|
||||||
"github.com/imgproxy/imgproxy/v3/imagedata"
|
"github.com/imgproxy/imgproxy/v3/imagedata"
|
||||||
"github.com/imgproxy/imgproxy/v3/logger"
|
"github.com/imgproxy/imgproxy/v3/logger"
|
||||||
"github.com/imgproxy/imgproxy/v3/memory"
|
"github.com/imgproxy/imgproxy/v3/memory"
|
||||||
@@ -30,6 +31,8 @@ func initialize() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gliblog.Init()
|
||||||
|
|
||||||
maxprocs.Set(maxprocs.Logger(log.Debugf))
|
maxprocs.Set(maxprocs.Logger(log.Debugf))
|
||||||
|
|
||||||
if err := config.Configure(); err != nil {
|
if err := config.Configure(); err != nil {
|
||||||
|
Reference in New Issue
Block a user