@@ -48,6 +48,7 @@ local byte = string.byte
48
48
49
49
50
50
local DOT_BYTE = byte (" ." )
51
+ local FFI_ERROR = require (" resty.core.base" ).FFI_ERROR
51
52
52
53
53
54
local _PREFIX = " [kong] "
@@ -58,6 +59,17 @@ local PHASES_LOG = PHASES.log
58
59
local QUESTION_MARK = byte (" ?" )
59
60
local TYPE_NAMES = constants .RESPONSE_SOURCE .NAMES
60
61
62
+
63
+ local ngx_lua_ffi_raw_log do
64
+ if ngx .config .subsystem == " http" or ngx .config .is_console then -- luacheck: ignore
65
+ ngx_lua_ffi_raw_log = require (" ffi" ).C .ngx_http_lua_ffi_raw_log
66
+
67
+ elseif ngx .config .subsystem == " stream" then
68
+ ngx_lua_ffi_raw_log = require (" ffi" ).C .ngx_stream_lua_ffi_raw_log
69
+ end
70
+ end
71
+
72
+
61
73
local phases_with_ctx =
62
74
phase_checker .new (PHASES .rewrite ,
63
75
PHASES .access ,
@@ -180,6 +192,21 @@ local serializers = {
180
192
end ,
181
193
}
182
194
195
+ local function raw_log_inspect (level , msg )
196
+ if type (level ) ~= " number" then
197
+ error (" bad argument #1 to 'raw_log' (must be a number)" , 2 )
198
+ end
199
+
200
+ if type (msg ) ~= " string" then
201
+ error (" bad argument #2 to 'raw_log' (must be a string)" , 2 )
202
+ end
203
+
204
+ local rc = ngx_lua_ffi_raw_log (nil , level , msg , # msg )
205
+ if rc == FFI_ERROR then
206
+ error (" bad log level" , 2 )
207
+ end
208
+ end
209
+
183
210
184
211
--- Writes a log line to the location specified by the current Nginx
185
212
-- configuration block's `error_log` directive, with the `notice` level (similar
@@ -363,7 +390,7 @@ local function gen_log_func(lvl_const, imm_buf, to_string, stack_level, sep)
363
390
local i = fullmsg :find (" \n " ) + 1
364
391
local header = fullmsg :sub (1 , i - 2 ) .. (" -" ):rep (WRAP - i + 3 ) .. " +"
365
392
366
- errlog . raw_log (lvl_const , header )
393
+ raw_log_inspect (lvl_const , header )
367
394
368
395
while i <= fullmsg_len do
369
396
local part = sub (fullmsg , i , i + WRAP - 1 )
@@ -378,10 +405,10 @@ local function gen_log_func(lvl_const, imm_buf, to_string, stack_level, sep)
378
405
end
379
406
380
407
part = part .. (" " ):rep (WRAP - # part )
381
- errlog . raw_log (lvl_const , " |" .. part .. " |" )
408
+ raw_log_inspect (lvl_const , " |" .. part .. " |" )
382
409
383
410
if i > fullmsg_len then
384
- errlog . raw_log (lvl_const , " +" .. (" -" ):rep (WRAP ) .. " +" )
411
+ raw_log_inspect (lvl_const , " +" .. (" -" ):rep (WRAP ) .. " +" )
385
412
end
386
413
end
387
414
0 commit comments