Skip to content

Commit

Permalink
[util] print stderr larger than 4kb
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Sep 13, 2018
1 parent d5c6448 commit 7513caa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gateway/src/apicast/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ local _M = {
local ngx_now = ngx.now

local len = string.len
local sub = string.sub
local errlog = require('ngx.errlog')

local open = io.open
local execute = os.execute
Expand Down Expand Up @@ -34,6 +36,8 @@ local function read(file)
return output
end

local max_log_line_len = 4096-96 -- 96 chars for our error message

function _M.system(command)
local tmpout = tmpname()
local tmperr = tmpname()
Expand All @@ -57,8 +61,13 @@ function _M.system(command)
-- os.execute returns exit code as first return value on OSX
-- even though the documentation says otherwise (true/false)
if success == 0 or success == true then
if len(tmperr) > 0 then
ngx.log(ngx.WARN, 'os execute stderr: \n', tmperr)
local max = len(tmperr)
if max > 0 then
errlog.raw_log(ngx.WARN, 'os execute stderr:')

for start=0, max , max_log_line_len do
errlog.raw_log(ngx.WARN, sub(tmperr, start, start + max_log_line_len - 1))
end
end

return tmpout
Expand Down

0 comments on commit 7513caa

Please sign in to comment.