From 6c85b8958d7a6537833aea9fb3aa1c831254128c Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Thu, 18 Feb 2021 12:52:39 +0200
Subject: [PATCH] lua/api: log using a debug category unique for the calling
 script file

filename: foo.lua -> category: script/foo
---
 modules/module-lua-scripting/api.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/modules/module-lua-scripting/api.c b/modules/module-lua-scripting/api.c
index 55e4dfc0..b9e7e0dc 100644
--- a/modules/module-lua-scripting/api.c
+++ b/modules/module-lua-scripting/api.c
@@ -163,7 +163,8 @@ static int
 log_log (lua_State *L, GLogLevelFlags lvl)
 {
   lua_Debug ar;
-  const gchar *message;
+  const gchar *message, *tmp;
+  gchar domain[25];
   gchar line_str[11];
   gconstpointer instance = NULL;
   GType type = G_TYPE_INVALID;
@@ -182,10 +183,14 @@ log_log (lua_State *L, GLogLevelFlags lvl)
   }
 
   message = luaL_checkstring (L, index);
-  sprintf (line_str, "%d", ar.currentline);
+  tmp = g_strrstr (ar.source, ".lua");
+  snprintf (domain, 25, "script/%.*s",
+      tmp ? MIN((gint)(tmp - ar.source), 17) : 17,
+      ar.source);
+  snprintf (line_str, 11, "%d", ar.currentline);
   ar.name = ar.name ? ar.name : "chunk";
 
-  wp_log_structured_standard (G_LOG_DOMAIN, lvl,
+  wp_log_structured_standard (domain, lvl,
       ar.source, line_str, ar.name, type, instance, "%s", message);
   return 0;
 }
-- 
GitLab