Redirect var/reports/* to stdout
-
14-04-2021 - |
Pergunta
I am using Magento 1.9 and want to redirect all the files generated inside the folder var/reports to stdout. If it is possible then how can I do it? If it is not then may be we can output all the generated reports files to one file and symlink to /dev/stdout. Any thoughts?
UPDATE:
I was able to create a file with name 9999 and redirect all logs to same file but when I tried to symlink the file to /dev/stdout
or /proc/self/fd/1
, both does not work. I still need the way to forward the logs to standard output.
To redirect logs to a single file, open errors/processor.php
file and edit two lines
//$this->reportId = abs(intval(microtime(true) * rand(100, 1000)));
$this->reportId = 9999;
and
//@file_put_contents($this->_reportFile, serialize($reportData));
@file_put_contents($this->_reportFile, serialize($reportData).PHP_EOL,FILE_APPEND|LOCK_EX);
Solução
The problem is solved. I was actually applying this for kubernetes and I needed to log in stdout. I followed the above updated steps and then use another container as sidecar, then tail
the output of 9999. It then gave me what I wanted.
I know this is not where I ask devops stuff but here is what sidecar container look like
- image: busybox
name: report-log
command: ["/bin/sh"]
args:
- -c
- |
mkdir -p /var/www/html/var/report
touch /var/www/html/var/report/9999
chown 33:33 /var/www/html/var -R
chmod 777 /var/www/html/var/ -R
tail -n+1 -f /var/www/html/var/report/9999
resources:
limits:
cpu: 5m
memory: 64Mi
requests:
cpu: 5m
memory: 64Mi
volumeMounts:
- name: reportlog
mountPath: /var/www/html/var/report
Also do not forget to mount volume as emptyDir. You can get the example here: https://kiwee.eu/magento-2-on-kubernetes/