Repository: sanic-org/sanic

Issue:
Turn off access log with gunicorn
Is there any way to turn off access log with gunicorn?
I could not find any example to set access_log=False with gunicorn.


Discussion:
By default, accesslog is None if i recall correctly
By default, access_log is True.
So, the only way i found to turn off access log is passing a log_config which without `"sanic.access"`.
did you try define your own `gunicorn_logconfig.ini` ?
@yunstanford Can you give an example how such a file should look like? I am unable to stop sanic.access log. I am using Gunicorn and Sanic on Heroku. No matter what I configure, I still see the access log if I tail the logs.


I have tried sanic with the default set up using gunicorn with the default configuration and sanic outputs twice the access logs, once in gunicorn and once with sanic.accesslog

https://github.com/channelcat/sanic/blob/818a8c2196fb14aab3ee30cd2fef845d0b7148ef/sanic/worker.py#L50-L70

But then in the Sanic's _helper function we have:

https://github.com/channelcat/sanic/blob/818a8c2196fb14aab3ee30cd2fef845d0b7148ef/sanic/app.py#L794-L800

So therefore the access log is always `True`

@yunstanford can you double check?

And then we maybe need to add this in the documentation :)

Resolving patch:
diff --git a/sanic/app.py b/sanic/app.py
--- a/sanic/app.py
+++ b/sanic/app.py
@@ -688,11 +688,12 @@ def run(self, host=None, port=None, debug=False, ssl=None,
                 warnings.simplefilter('default')
             warnings.warn("stop_event will be removed from future versions.",
                           DeprecationWarning)
+        # compatibility old access_log params
+        self.config.ACCESS_LOG = access_log
         server_settings = self._helper(
             host=host, port=port, debug=debug, ssl=ssl, sock=sock,
             workers=workers, protocol=protocol, backlog=backlog,
-            register_sys_signals=register_sys_signals,
-            access_log=access_log, auto_reload=auto_reload)
+            register_sys_signals=register_sys_signals, auto_reload=auto_reload)
 
         try:
             self.is_running = True
@@ -746,12 +747,12 @@ async def create_server(self, host=None, port=None, debug=False,
                 warnings.simplefilter('default')
             warnings.warn("stop_event will be removed from future versions.",
                           DeprecationWarning)
-
+        # compatibility old access_log params
+        self.config.ACCESS_LOG = access_log
         server_settings = self._helper(
             host=host, port=port, debug=debug, ssl=ssl, sock=sock,
             loop=get_event_loop(), protocol=protocol,
-            backlog=backlog, run_async=True,
-            access_log=access_log)
+            backlog=backlog, run_async=True)
 
         # Trigger before_start events
         await self.trigger_events(
@@ -796,8 +797,7 @@ async def _run_response_middleware(self, request, response):
     def _helper(self, host=None, port=None, debug=False,
                 ssl=None, sock=None, workers=1, loop=None,
                 protocol=HttpProtocol, backlog=100, stop_event=None,
-                register_sys_signals=True, run_async=False, access_log=True,
-                auto_reload=False):
+                register_sys_signals=True, run_async=False, auto_reload=False):
         """Helper function used by `run` and `create_server`."""
         if isinstance(ssl, dict):
             # try common aliaseses
@@ -838,7 +838,7 @@ def _helper(self, host=None, port=None, debug=False,
             'loop': loop,
             'register_sys_signals': register_sys_signals,
             'backlog': backlog,
-            'access_log': access_log,
+            'access_log': self.config.ACCESS_LOG,
             'websocket_max_size': self.config.WEBSOCKET_MAX_SIZE,
             'websocket_max_queue': self.config.WEBSOCKET_MAX_QUEUE,
             'websocket_read_limit': self.config.WEBSOCKET_READ_LIMIT,
diff --git a/sanic/config.py b/sanic/config.py
--- a/sanic/config.py
+++ b/sanic/config.py
@@ -39,6 +39,7 @@ def __init__(self, defaults=None, load_env=True, keep_alive=True):
         self.WEBSOCKET_READ_LIMIT = 2 ** 16
         self.WEBSOCKET_WRITE_LIMIT = 2 ** 16
         self.GRACEFUL_SHUTDOWN_TIMEOUT = 15.0  # 15 sec
+        self.ACCESS_LOG = True
 
         if load_env:
             prefix = SANIC_PREFIX if load_env is True else load_env


Test patch: