cooldude101
cooldude101

Reputation: 1405

How to write to STD / docker logs from the wordpress docker image in PHP?

if I use error_log('hello'); it writes to /proc/1/fd/2, but how do I get /proc/1/fd/2 to output to STD / docker logs?

my code:

add_action('init', function () {
  error_log('hello');
})

my docker compose:

version: '3.3'
services:
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "80:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: password

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: user
      MYSQL_DATABASE: user
      MYSQL_USER: user
      MYSQL_PASSWORD: password

Upvotes: 2

Views: 1278

Answers (1)

abestrad
abestrad

Reputation: 906

Docker logs shows the command’s STDOUT and STDERR by default. So, try something like:

file_put_contents('php://stderr', 'Your text goes to STDERR',FILE_APPEND);

source:

Upvotes: 1

Related Questions