change print to log

This commit is contained in:
李勇
2021-07-24 16:46:22 +08:00
parent c73ec1a1f3
commit 9bf341f6a5
+13 -20
View File
@@ -8,9 +8,9 @@ local form, err = upload:new(chunk_size)
local output_image_filename_uuid = uuid.generate(); local output_image_filename_uuid = uuid.generate();
if not form then if not form then
ngx.log(ngx.ERR, "failed to new upload: ", err) ngx.log(ngx.ERR, "failed to new upload: ", err)
ngx.say("failed to new upload: ", err)
ngx.exit(500) ngx.exit(500)
end end
@@ -42,7 +42,7 @@ local upload_image_index = 1
while true do while true do
local typ, res, err = form:read() local typ, res, err = form:read()
if not typ then if not typ then
ngx.say("failed to read: ", err) ngx.log(ngx.ERR, "failed to read: ", err)
return return
end end
if typ == "header" then if typ == "header" then
@@ -60,8 +60,7 @@ while true do
local kvfile = string.split(seg, "=") local kvfile = string.split(seg, "=")
upload_image_filename = string.sub(kvfile[2], 2, -2) upload_image_filename = string.sub(kvfile[2], 2, -2)
ngx.say(" -->> POST : Upload origin image is ", upload_image_filename) ngx.log(ngx.INFO,"Upload origin image is ", upload_image_filename)
ngx.say("\n")
if upload_image_filename then if upload_image_filename then
-- Save file name with generate uuid -- Save file name with generate uuid
@@ -69,15 +68,13 @@ while true do
save_image_filename = save_image_filename .. '.' .. upload_image_filename:match(".+%.(%w+)$") save_image_filename = save_image_filename .. '.' .. upload_image_filename:match(".+%.(%w+)$")
fileToSave = io.open(saveRootPath .. save_image_filename, "w+") fileToSave = io.open(saveRootPath .. save_image_filename, "w+")
if not fileToSave then if not fileToSave then
ngx.say(" Error: Failed to open file ", save_image_filename) ngx.log(ngx.ERR, " Error: Failed to open file ", save_image_filename)
return return
else else
ngx.say("Open file ok ", save_image_filename) ngx.log(ngx.INFO, "Open file ok ", save_image_filename)
ngx.say("\n")
upload_image_table[upload_image_index] = saveRootPath .. save_image_filename .. " " upload_image_table[upload_image_index] = saveRootPath .. save_image_filename .. " "
ngx.say("Insert upload image table "..upload_image_index.." with "..upload_image_table[upload_image_index]) ngx.log(ngx.INFO, "Insert upload image table "..upload_image_index.." with "..upload_image_table[upload_image_index])
ngx.say("\n")
upload_image_index = upload_image_index + 1 upload_image_index = upload_image_index + 1
end end
@@ -107,36 +104,32 @@ while true do
end end
end end
if ret_save then if ret_save then
ngx.say("Show all upload files\n") ngx.log(ngx.INFO, "Show all upload files\n")
-- Show all upload files -- Show all upload files
upload_image_index = upload_image_index -1 upload_image_index = upload_image_index -1
for i = 1, upload_image_index do for i = 1, upload_image_index do
ngx.say("Save upload file is : " .. upload_image_table[i]) ngx.log(ngx.INFO, "Save upload file is : " .. upload_image_table[i])
ngx.say("\n")
end end
image_append_coroutine = coroutine.create( image_append_coroutine = coroutine.create(
function () function ()
-- Append images -- Append images
-- ngx.say("Upload image number is : " , upload_image_index ) -- ngx.log(ngx.INFO,"Upload image number is : " , upload_image_index )
local append_images_path local append_images_path
append_images_path = table.concat(upload_image_table) append_images_path = table.concat(upload_image_table)
ngx.say("Input images list : " , append_images_path) ngx.log(ngx.INFO, "Input images list : " , append_images_path)
ngx.say("\n")
-- local append_output_image = saveRootPath .. uuid.generate()..".jpg "; -- local append_output_image = saveRootPath .. uuid.generate()..".jpg ";
local append_output_image = saveRootPath .. output_image_filename_uuid..".jpg "; local append_output_image = saveRootPath .. output_image_filename_uuid..".jpg ";
ngx.say("Output image is : "..append_output_image) ngx.log(ngx.INFO, "Output image is : "..append_output_image)
ngx.say("\n")
-- Debug -- Debug
ngx.say('/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image) ngx.log(ngx.INFO, '/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image)
ngx.say("\n")
local call_imagemagick_cmd = io.popen('/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image) local call_imagemagick_cmd = io.popen('/usr/local/ImageMagick/bin/magick convert -append '..append_images_path..' '..append_output_image)
local imagemagick_cmd_replay = call_imagemagick_cmd:read("*all") local imagemagick_cmd_replay = call_imagemagick_cmd:read("*all")
ngx.say(imagemagick_cmd_replay) ngx.log(ngx.INFO, imagemagick_cmd_replay)
end end