[SOLVED] Docker Logging

Has anyone managed to redirect the openhab logs to Docker logs?

I know that Docker logs use stdout for pid 1 but I have struggled to achieve the goal. I have tried:

  • Symbolic linking of openhab.log to stdout
  • tail of the openhab.log

But no luck so far.

In unifi I have a logs container:

  logs:
    image: bash
    depends_on:
      - controller
    command: bash -c 'tail -f /unifi/log/*'
    restart: always
    volumes:
      - log:/unifi/log

The important bit is - log:/unifi/log this has to be the same volume (named volume) as where unifi wirtes it’s logs to.

I think you could do the same with openhab.

Set the logs of openhab to:

volumes:
   - log:/openhab/userdata/logs

Create the log container:

  ohlogs:
    image: bash
    depends_on:
      - controller
    command: bash -c 'tail -f /openhab/*'
    restart: always
    volumes:
      - log:/openhab/

Then the openhab logs container would have all the logs for you (that you can then run `docker logs -f ohlogs’

I haven’t tried this, but there’s no reason it wouldn’t work.

Just add a console logger like explained in the readme:

4 Likes

Thanks all.

I’ll give it a go.

Works like a charm. Thanks!

1 Like