question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"log to local file" not working in container

See original GitHub issue

I try to extend some logic to make the log saved to files, but it wouldn’t work with docker-compose. Here are my steps:

  1. Modify tasks\__init__.py with RotatingFileHandler
...
    for handler in logger.handlers:
        if isinstance(handler, logging.StreamHandler):
            break
    else:
        handler = logging.StreamHandler()
        logger.addHandler(handler)
    formatter.converter = time.gmtime
    handler.setFormatter(formatter)
    handler.addFilter(RequestIDLogFilter())
    
    # Log to file handler
    if not os.path.exists('LogFolder'):
        os.makedirs('LogFolder')  
    handler = RotatingFileHandler(datetime.datetime.utcnow().strftime("LogFolder/%Y_%m_%d.log"), maxBytes=50*1024*1024, backupCount=999)
    handler.setFormatter(formatter)
    handler.addFilter(RequestIDLogFilter())
    logger.addHandler(handler)

from invoke import Collection
...
  1. Run with docker-compose
$ cd deploy/stack2
$ docker-compose build
$ docker-compose up

Then I could only got log inside stack2_api container like below and no more newer:

/opt/www $ cat LogFolder/2017_12_25.log
2017-12-25 12:40:25,180 [None][WARNING] [tasks.app.db] Alembic cannot be imported, so some app.db.* tasks won't be available!
2017-12-25 12:40:25,239 [None][INFO] [tasks.app.dependencies] Installing project dependencies...
2017-12-25 12:41:10,636 [None][INFO] [tasks.app.dependencies] Project dependencies are installed.
2017-12-25 12:41:10,637 [None][INFO] [tasks.app.dependencies] Installing Swagger UI assets...
2017-12-25 12:41:10,638 [None][INFO] [tasks.app.dependencies] Downloading Swagger UI assets...
2017-12-25 12:41:10,721 [None][INFO] [tasks.utils] Downloading a file from 'https://github.com/swagger-api/swagger-ui/archive/v2.2.10.zip' to '/opt/www/static/bower/swagger-ui.zip'
2017-12-25 12:41:17,668 [None][INFO] [tasks.app.dependencies] Unpacking Swagger UI assets...
2017-12-25 12:41:17,730 [None][INFO] [tasks.app.dependencies] Swagger UI is installed.

But It worked great without container, did I do anything wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
MagicJohnJangcommented, Dec 26, 2017

I just found out that the logs worked on deploy/stack1 , I think there might be some problem with my stack2 uWSGI.

Actually I got the stack2 message output after docker-compose up as below:

...
api_1       | !!! no internal routing support, rebuild with pcre support !!!
api_1       | *** WARNING: you are running uWSGI without its master process manager ***
api_1       | your memory page size is 4096 bytes
api_1       | detected max file descriptor number: 1048576
api_1       | lock engine: pthread robust mutexes
api_1       | thunder lock: disabled (you can enable it with --thunder-lock)
api_1       | uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 3
api_1       | Python version: 3.6.3 (default, Nov 21 2017, 14:55:19)  [GCC 6.4.0]
api_1       | *** Python threads support is disabled. You can enable it with --enable-threads ***
...

Let me fix that up, and I will keep my updates here to let you know 😛

0reactions
frolcommented, Jan 16, 2018

I am closing this since this use-case is now documented in the PRs made by @MagicJohnJang

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local File logging driver - Docker Documentation
The local logging driver captures output from container's stdout/stderr and writes them to an internal storage that is optimized for performance and disk...
Read more >
Logging to host from Docker container does not work
So the file will be created and can be seen both from container and host machine. What am I doing wrong? I think,...
Read more >
Where Are Docker Container Logs Stored? - Sematext
Let's start debugging. First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you...
Read more >
Understanding Docker Logging and Log Files - Earthly Blog
When a Docker container broadcasts logs, it sends them to the application's stdout and stderr output streams. The underlying container logging ...
Read more >
Writing and Managing Application Logs with Docker - Manning
If you're running Docker CE on Linux or you're using Windows containers then the path to the log file is on your local...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found