snippetdockerMinor
How do I convert "\n" to linebreaks in my docker logs?
Viewed 0 times
logsconvertdockerhowlinebreaks
Problem
I am using
```
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/BlockPluginCollect
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/BlockPluginCollect
Solution
Try to read logs as follows:
[NOTE]:
docker logs -f 2>&1[NOTE]:
-foption follows live logs.
2>&1makes output asstdoutandstderrwhich is useful for grepping and standardizing.
Code Snippets
docker logs -f <container-name or container-ID> 2>&1Context
StackExchange DevOps Q#12392, answer score: 2
Revisions (0)
No revisions yet.