<p>Try to read logs as follows:</p>
<pre><code>docker logs -f &lt;container-name or container-ID&gt; 2&gt;&amp;1
</code></pre>
<hr />
<p>[<strong>NOTE</strong>]:</p>
<ul>
<li><code>-f</code> option follows live logs.</li>
<li><code>2&gt;&amp;1</code> makes output as <code>stdout</code> and <code>stderr</code> which is useful for grepping and standardizing.</li>
</ul>

CC BY-SA 4.0
2020-09-14T07:04:51.120Z
2020-09-22T07:12:25.113Z
2020-09-22T07:12:25.113Z
Benyamin Jafari
<p>I am using <code>docker-compose up</code> to start a web server in linux but am finding that the <code>stdout</code> is printing &quot;\n&quot; characters instead of creating new lines. This makes stack traces difficult to read;</p>
<pre><code>172.19.0.1 - - [12/Sep/2020:02:19:18 +0000] &quot;GET /node/100 HTTP/1.1&quot; 500 337 &quot;http://localhost/node/100/edit&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36&quot;
[Sat Sep 12 02:19:18.426082 2020] [php7:notice] [pid 21] [client 172.19.0.1:58954] ParseError: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting identifier (T_STRING) in /opt/drupal/web/modules/custom/rsvplist/src/Plugin/Block/RSVPBlock.php on line 37 #0 /opt/drupal/vendor/composer/ClassLoader.php(322): Composer\\Autoload\\includeFile('/opt/drupal/web...')\n#1 [internal function]: Composer\\Autoload\\ClassLoader-&gt;loadClass('Drupal\\\\rsvplist...')\n#2 [internal function]: spl_autoload_call('Drupal\\\\rsvplist...')\n#3 /opt/drupal/web/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php(96): class_exists('Drupal\\\\rsvplist...')\n#4 /opt/drupal/web/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php(17): Drupal\\Component\\Plugin\\Factory\\DefaultFactory::getPluginClass('rsvp_block', Array, 'Drupal\\\\Core\\\\Blo...')\n#5 /opt/drupal/web/core/lib/Drupal/Component/Plugin/PluginManagerBase.php(76): Drupal\\Core\\Plugin\\Factory\\ContainerFactory-&gt;createInstance('rsvp_block', Array)\n#6 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(62): Drupal\\Component\\Plugin\\PluginManagerBase-&gt;createInstance('rsvp_block', Array)\n#7 /opt/drupal/web/core/modules/block/src/BlockPluginCollection.php(57): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection-&gt;initializePlugin('rsvp_block')\n#8 /opt/drupal/web/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php(80): Drupal\\block\\BlockPluginCollection-&gt;initializePlugin('rsvp_block')\n#9 /opt/drupal/web/core/modules/block/src/BlockPluginCollection.php(45): Drupal\\Component\\Plugin\\LazyPluginCollection-&gt;get('rsvp_block')\n#10 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(83): Drupal\\block\\BlockPluginCollection-&gt;get('rsvp_block')\n#11 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(99): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection-&gt;setConfiguration(Array)\n#12 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(55): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection-&gt;addInstanceId('rsvp_block', Array)\n#13 /opt/drupal/web/core/modules/block/src/BlockPluginCollection.php(34): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection-&gt;__construct(Object(Drupal\\Core\\Block\\BlockManager), 'rsvp_block', Array)\n#14 /opt/drupal/web/core/modules/block/src/Entity/Block.php(156): Drupal\\block\\BlockPluginCollection-&gt;__construct(Object(Drupal\\Core\\Block\\BlockManager), 'rsvp_block', Array, 'rsvpblock')\n#15 /opt/drupal/web/core/modules/block/src/Entity/Block.php(145): Drupal\\block\\Entity\\Block-&gt;getPluginCollection()\n#16 /opt/drupal/web/core/modules/block/src/BlockAccessControlHandler.php(118): Drupal\\block\\Entity\\Block-&gt;getPlugin()\n#17 /opt/drupal/web/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php(105): Drupal\\block\\BlockAccessControlHandler-&gt;checkAccess(Object(Drupal\\block\\Entity\\Block), 'view', Object(Drupal\\Core\\Session\\AccountProxy))\n#18 /opt/drupal/web/core/lib/Drupal/Core/Entity/EntityBase.php(314): Drupal\\Core\\Entity\\EntityAccessControlHandler-&gt;access(Object(Drupal\\block\\Entity\\Block), 'view', Object(Drupal\\Core\\Session\\AccountProxy), true)\n#19 /opt/drupal/web/core/modules/block/src/BlockRepository.php(56): Drupal\\Core\\Entity\\EntityBase-&gt;access('view', NULL, true)\n#20 /opt/drupal/web/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php(137): Drupal\\block\\BlockRepository-&gt;getVisibleBlocksPerRegion(Array)\n#21 /opt/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(259): Drupal\\block\\Plugin\\DisplayVariant\\BlockPageVariant-&gt;build()\n#22 /opt/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\\Core\\Render\\MainContent\\HtmlRenderer-&gt;prepare(Array, Object(Symfony\\Component\\HttpFoundation\\Request), Object(Drupal\\Core\\Routing\\CurrentRouteMatch))\n#23 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\\Core\\Render\\MainContent\\HtmlRenderer-&gt;renderResponse(Array, Object(Symfony\\Component\\HttpFoundation\\Request), Object(Drupal\\Core\\Routing\\CurrentRouteMatch))\n#24 /opt/drupal/vendor/symfony/event-dispatcher/LegacyEventDispatcherProxy.php(78): Drupal\\Core\\EventSubscriber\\MainContentViewSubscriber-&gt;onViewRenderArray(Object(Symfony\\Component\\HttpKernel\\Event\\ViewEvent), 'kernel.view', Object(Symfony\\Component\\EventDispatcher\\LegacyEventDispatcherProxy))\n#25 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(163): Symfony\\Component\\EventDispatcher\\LegacyEventDispatcherProxy-&gt;dispatch(Object(Symfony\\Component\\HttpKernel\\Event\\ViewEvent), 'kernel.view')\n#26 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\\Component\\HttpKernel\\HttpKernel-&gt;handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#27 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\\Component\\HttpKernel\\HttpKernel-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#28 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\\Core\\StackMiddleware\\Session-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#29 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#30 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache-&gt;pass(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#31 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\\page_cache\\StackMiddleware\\PageCache-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#32 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#33 /opt/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#34 /opt/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(705): Stack\\StackedHttpKernel-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#35 /opt/drupal/web/index.php(19): Drupal\\Core\\DrupalKernel-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#36 {main}, referer: http://localhost/node/100/edit
172.19.0.1 - - [12/Sep/2020:02:19:18 +0000] &quot;GET /node/100 HTTP/1.1&quot; 500 337 &quot;http://localhost/node/100/edit&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36&quot;
</code></pre>
<p>I am unsure whether this is a &quot;Docker&quot; or a &quot;Unix&quot; question. Ideally there would be some kind of setting I can use to make <code>docker run</code> respect unix line endings, but I'm also open to other solutions.</p>

<docker><docker-compose><linux>
How do I convert "\n" to linebreaks in my docker logs?
quant
# How do I convert "\n" to linebreaks in my docker logs?

(Asked by: username_0 on 2020-09-12)

I am using docker-compose up to start a web server in linux but am finding that the stdout is printing "\n" characters instead of creating new lines. This makes stack traces difficult to read;
172.19.0.1 - - [12/Sep/2020:02:19:18 +0000] "GET /node/100 HTTP/1.1" 500 337 "http://localhost/node/100/edit" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
[Sat Sep 12 02:19:18.426082 2020] [php7:notice] [pid 21] [client 172.19.0.1:58954] ParseError: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting identifier (T_STRING) in /opt/drupal/web/modules/custom/rsvplist/src/Plugin/Block/RSVPBlock.php on line 37 #0 /opt/drupal/vendor/composer/ClassLoader.php(322): Composer\\Autoload\\includeFile('/opt/drupal/web...')\n#1 [internal function]: Composer\\Autoload\\ClassLoader->loadClass('Drupal\\\\rsvplist...')\n#2 [internal function]: spl_autoload_call('Drupal\\\\rsvplist...')\n#3 /opt/drupal/web/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php(96): class_exists('Drupal\\\\rsvplist...')\n#4 /opt/drupal/web/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php(17): Drupal\\Component\\Plugin\\Factory\\DefaultFactory::getPluginClass('rsvp_block', Array, 'Drupal\\\\Core\\\\Blo...')\n#5 /opt/drupal/web/core/lib/Drupal/Component/Plugin/PluginManagerBase.php(76): Drupal\\Core\\Plugin\\Factory\\ContainerFactory->createInstance('rsvp_block', Array)\n#6 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(62): Drupal\\Component\\Plugin\\PluginManagerBase->createInstance('rsvp_block', Array)\n#7 /opt/drupal/web/core/modules/block/src/BlockPluginCollection.php(57): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection->initializePlugin('rsvp_block')\n#8 /opt/drupal/web/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php(80): Drupal\\block\\BlockPluginCollection->initializePlugin('rsvp_block')\n#9 /opt/drupal/web/core/modules/block/src/BlockPluginCollection.php(45): Drupal\\Component\\Plugin\\LazyPluginCollection->get('rsvp_block')\n#10 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(83): Drupal\\block\\BlockPluginCollection->get('rsvp_block')\n#11 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(99): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection->setConfiguration(Array)\n#12 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php(55): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection->addInstanceId('rsvp_block', Array)\n#13 /opt/drupal/web/core/modules/block/src/BlockPluginCollection.php(34): Drupal\\Core\\Plugin\\DefaultSingleLazyPluginCollection->__construct(Object(Drupal\\Core\\Block\\BlockManager), 'rsvp_block', Array)\n#14 /opt/drupal/web/core/modules/block/src/Entity/Block.php(156): Drupal\\block\\BlockPluginCollection->__construct(Object(Drupal\\Core\\Block\\BlockManager), 'rsvp_block', Array, 'rsvpblock')\n#15 /opt/drupal/web/core/modules/block/src/Entity/Block.php(145): Drupal\\block\\Entity\\Block->getPluginCollection()\n#16 /opt/drupal/web/core/modules/block/src/BlockAccessControlHandler.php(118): Drupal\\block\\Entity\\Block->getPlugin()\n#17 /opt/drupal/web/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php(105): Drupal\\block\\BlockAccessControlHandler->checkAccess(Object(Drupal\\block\\Entity\\Block), 'view', Object(Drupal\\Core\\Session\\AccountProxy))\n#18 /opt/drupal/web/core/lib/Drupal/Core/Entity/EntityBase.php(314): Drupal\\Core\\Entity\\EntityAccessControlHandler->access(Object(Drupal\\block\\Entity\\Block), 'view', Object(Drupal\\Core\\Session\\AccountProxy), true)\n#19 /opt/drupal/web/core/modules/block/src/BlockRepository.php(56): Drupal\\Core\\Entity\\EntityBase->access('view', NULL, true)\n#20 /opt/drupal/web/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php(137): Drupal\\block\\BlockRepository->getVisibleBlocksPerRegion(Array)\n#21 /opt/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(259): Drupal\\block\\Plugin\\DisplayVariant\\BlockPageVariant->build()\n#22 /opt/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\\Core\\Render\\MainContent\\HtmlRenderer->prepare(Array, Object(Symfony\\Component\\HttpFoundation\\Request), Object(Drupal\\Core\\Routing\\CurrentRouteMatch))\n#23 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\\Core\\Render\\MainContent\\HtmlRenderer->renderResponse(Array, Object(Symfony\\Component\\HttpFoundation\\Request), Object(Drupal\\Core\\Routing\\CurrentRouteMatch))\n#24 /opt/drupal/vendor/symfony/event-dispatcher/LegacyEventDispatcherProxy.php(78): Drupal\\Core\\EventSubscriber\\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\\Component\\HttpKernel\\Event\\ViewEvent), 'kernel.view', Object(Symfony\\Component\\EventDispatcher\\LegacyEventDispatcherProxy))\n#25 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(163): Symfony\\Component\\EventDispatcher\\LegacyEventDispatcherProxy->dispatch(Object(Symfony\\Component\\HttpKernel\\Event\\ViewEvent), 'kernel.view')\n#26 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#27 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#28 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\\Core\\StackMiddleware\\Session->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#29 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#30 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache->pass(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#31 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\\page_cache\\StackMiddleware\\PageCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#32 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#33 /opt/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#34 /opt/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(705): Stack\\StackedHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#35 /opt/drupal/web/index.php(19): Drupal\\Core\\DrupalKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#36 {main}, referer: http://localhost/node/100/edit
172.19.0.1 - - [12/Sep/2020:02:19:18 +0000] "GET /node/100 HTTP/1.1" 500 337 "http://localhost/node/100/edit" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"

I am unsure whether this is a "Docker" or a "Unix" question. Ideally there would be some kind of setting I can use to make docker run respect unix line endings, but I'm also open to other solutions.

**Tags:** docker, docker-compose, linux


---

## 1 answers

### Answer by username_1 on 2020-09-14. Score: 2 | Accepted answer

Try to read logs as follows:
docker logs -f  2>&1


[NOTE]:

-f option follows live logs.
2>&1 makes output as stdout and stderr which is useful for grepping and standardizing.


---

