|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + "description": "Plone 6 Docker image recipes" |
| 5 | + "property=og:description": "Plone 6 Docker image recipes" |
| 6 | + "property=og:title": "Plone 6 Image recipes" |
| 7 | + "keywords": "Plone 6, install, installation, docker, containers, Official Images" |
| 8 | +--- |
| 9 | + |
| 10 | +# Recipes |
| 11 | + |
| 12 | +Here you have some useful recipes when working with Plone containers |
| 13 | + |
| 14 | + |
| 15 | +## Remove access log from plone containers |
| 16 | + |
| 17 | +When working a project generated using [cookieplone](https://github.com/plone/cookieplone) you will be creating Plone containers for your project that are based on the official `plone/plone-backend` images. |
| 18 | + |
| 19 | +You may have noted that when you run your container or the official `plone/plone-backend` image, the output mixes both the event log and the access log making it hard to follow the logs you may have added to your application. |
| 20 | + |
| 21 | +In such cases, you may end with a `docker compose` setup with several components in which you will have a proxy server that already provides access logs. |
| 22 | + |
| 23 | +So it is a common usage configuration to remove the access logging from the Plone container. |
| 24 | + |
| 25 | +To do so you will need a custom {file}`zope.ini` file in your project's {file}`backend` folder with the following content: |
| 26 | + |
| 27 | +```ini |
| 28 | +[app:zope] |
| 29 | +use = egg:Zope#main |
| 30 | +zope_conf = %(here)s/%(config_file)s |
| 31 | + |
| 32 | +[server:main] |
| 33 | +use = egg:waitress#main |
| 34 | +host = 0.0.0.0 |
| 35 | +port = 8080 |
| 36 | +threads = 2 |
| 37 | +clear_untrusted_proxy_headers = false |
| 38 | +max_request_body_size = 1073741824 |
| 39 | + |
| 40 | + |
| 41 | +[filter:translogger] |
| 42 | +use = egg:Paste#translogger |
| 43 | +setup_console_handler = False |
| 44 | + |
| 45 | +[pipeline:main] |
| 46 | +pipeline = |
| 47 | + egg:Zope#httpexceptions |
| 48 | + zope |
| 49 | + |
| 50 | +[loggers] |
| 51 | +keys = root, waitress.queue, waitress, wsgi |
| 52 | + |
| 53 | +[handlers] |
| 54 | +keys = accesslog, eventlog |
| 55 | + |
| 56 | +[formatters] |
| 57 | +keys = generic, message |
| 58 | + |
| 59 | +[formatter_generic] |
| 60 | +format = %(asctime)s %(levelname)s [%(name)s:%(lineno)s][%(threadName)s] %(message)s |
| 61 | +datefmt = %Y-%m-%d %H:%M:%S |
| 62 | + |
| 63 | +[formatter_message] |
| 64 | +format = %(message)s |
| 65 | + |
| 66 | +[logger_root] |
| 67 | +level = INFO |
| 68 | +handlers = eventlog |
| 69 | + |
| 70 | +[logger_waitress.queue] |
| 71 | +level = INFO |
| 72 | +handlers = eventlog |
| 73 | +qualname = waitress.queue |
| 74 | +propagate = 0 |
| 75 | + |
| 76 | +[logger_waitress] |
| 77 | +level = INFO |
| 78 | +handlers = eventlog |
| 79 | +qualname = waitress |
| 80 | +propagate = 0 |
| 81 | + |
| 82 | +[logger_wsgi] |
| 83 | +level = WARN |
| 84 | +handlers = accesslog |
| 85 | +qualname = wsgi |
| 86 | +propagate = 0 |
| 87 | + |
| 88 | +[handler_accesslog] |
| 89 | +class = StreamHandler |
| 90 | +args = (sys.stdout,) |
| 91 | +level = INFO |
| 92 | +formatter = message |
| 93 | + |
| 94 | +[handler_eventlog] |
| 95 | +class = StreamHandler |
| 96 | +args = (sys.stderr,) |
| 97 | +level = INFO |
| 98 | +formatter = generic |
| 99 | + |
| 100 | +``` |
| 101 | + |
| 102 | +If you compare this file with the [original zope.ini file](https://github.com/plone/plone-backend/blob/6.1.x/skeleton/etc/zope.ini) that comes with the `plone/plone-backend` container, you may realize that the only change here is that we remove `translogger` from the `pipeline` option. |
| 103 | + |
| 104 | +This `translogger` middleware [produces logs in the Apache Combined Log Format](https://docs.pylonsproject.org/projects/waitress/en/latest/logging.html) and that is exactly what we want to remove in our setup. |
| 105 | + |
| 106 | +After adding the mentioned file in your project, you need to adjust the {file}`Dockerfile` also. |
| 107 | + |
| 108 | + |
| 109 | +In your {file}`Dockerfile` you have the following contents: |
| 110 | + |
| 111 | +```Dockerfile |
| 112 | +... |
| 113 | +# Add local code |
| 114 | +COPY scripts/ scripts/ |
| 115 | +COPY . src |
| 116 | + |
| 117 | +# Install local requirements and pre-compile mo files |
| 118 | +RUN <<EOT |
| 119 | +... |
| 120 | +``` |
| 121 | + |
| 122 | +Just before the `RUN` command, you need to copy the {file}`zope.ini` file into the container, as follows: |
| 123 | + |
| 124 | +```Dockerfile |
| 125 | +... |
| 126 | +# Add local code |
| 127 | +COPY scripts/ scripts/ |
| 128 | +COPY . src |
| 129 | +COPY zope.ini etc/ |
| 130 | + |
| 131 | +# Install local requirements and pre-compile mo files |
| 132 | +RUN <<EOT |
| 133 | +``` |
| 134 | + |
| 135 | +With these changes, after you build your project container as usual, it will not output the access log, but only the event log. |
| 136 | + |
0 commit comments