You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/08 06:33:58 UTC

[GitHub] [apisix] bzp2010 commented on a diff in pull request #7884: fix(file-loger): use no buffering model when open file

bzp2010 commented on code in PR #7884:
URL: https://github.com/apache/apisix/pull/7884#discussion_r965557052


##########
apisix/plugins/file-logger.lua:
##########
@@ -116,11 +119,16 @@ local function write_file_data(conf, log_message)
     if not file then
         core.log.error("failed to open file: ", conf.path, ", error info: ", err)
     else
-        local ok, err = file:write(msg, '\n')
+        -- file:write(msg, "\n") will call fwrite several times
+        -- which will cause problem with the log output
+        -- it should be atomic
+        msg = msg .. "\n"
+        local ok, err = file:write(msg)
         if not ok then
             core.log.error("failed to write file: ", conf.path, ", error info: ", err)
         else
-            file:flush()
+            -- No buffering model don't need flush, write to file directly
+            -- file:flush()

Review Comment:
   If they are no longer needed, do we need to delete it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org