"log to local file" not working in container
See original GitHub issueI try to extend some logic to make the log saved to files, but it wouldn’t work with docker-compose. Here are my steps:
- Modify
tasks\__init__.py
withRotatingFileHandler
...
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
...
- 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:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:Let me fix that up, and I will keep my updates here to let you know 😛
I am closing this since this use-case is now documented in the PRs made by @MagicJohnJang