์๋ ,
http://docs.gunicorn.org/en/stable/settings.html#accesslog ๋ '-'
๊ฐ stderr๋ก ์ถ๋ ฅ๋ ๊ฒ์ด๋ผ๊ณ ๋งํ๊ณ ์์ง๋ง ์ฐ๋ฆฌ๋ ๋ก๊น
๋ชฉ์ ์ผ๋ก STDOUT์ ์ ํธํฉ๋๋ค. ๊ทธ๊ฒ์ ํ ์์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๊ฐ์ฌ ํด์!
๊ด๋ จ ๋ผ์ธ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. https://github.com/benoitc/gunicorn/blame/master/gunicorn/glogging.py#L335 logging.StreamHandler()
๊ธฐ๋ณธ๊ฐ์ sys.stderr
์
๋๋ค. ์๋ง๋ "stdout" ๋ฐ "stderr"์ ์ ํจํ ๊ฐ์ผ๋ก ๋ฐ์๋ค์ด๊ณ logging.StreamHandler()
์ ์ ๋ฌํ๋๋ก accesslog๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
์ ์ฐํ์ง ์์ ๋ ๋ค๋ฅธ ์๋ฃจ์ :
์ฝ์ ํธ๋ค๋ฌ๋ ์ด๋ฏธ sys.stdout
๋ก ์ธ์๋ฉ๋๋ค. https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L64 gunicorn.accesslog
์ ๋ํด ํธ๋ค๋ฌ๋ฅผ "console"๋ก ์ค์ ํ ์ ์์ต๋๋ค. https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L55 ์์ ์ด๋ฏธ gunicorn.error
์ ๋ํด ํ๋ ๊ฒ์ฒ๋ผ
ํผ๋์ค๋ฌ์์. StreamHandler๊ฐ ์ด๋ฏธ sys.stdout์ ๋ก๊ทธ์จํ์ง ์์ต๋๊น?
์๋์, ๊ธฐ๋ณธ๊ฐ์ sys.stderr
์
๋๋ค. https://github.com/python/cpython/blob/master/Lib/logging/__init__.py#L955
์์์ด ์ด์ ์ดํด ํ์ด. ์๋ ์ฐ๋ฆฌ๋ stdout์ ๋ก๊ทธ๋ฅผ ์ธ์ํ๊ณ ์์์ต๋๋ค. IMO ์ก์ธ์ค ๋ก๊ทธ๋ ๊ธฐ๋ณธ์ ์ผ๋ก STDOUT์ด์ด์ผ ํฉ๋๋ค. ์๊ฐ?
@benoitc :+1:
stdout์ ๋ํ ์ก์ธ์ค ๋ก๊ทธ
stderr์ ๋ํ ์ค๋ฅ ๋ก๊ทธ
์ด ์์ฒญ์ ๋ํ ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น?
@benoitc ์ด ์ปค๋ฐ์ด ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋์ง ํ์ ํ ์ ์์ต๋๋ค. ์ถ๊ฐ ์ธ์ ์์ด gunicorn myapp:app
๋ฅผ ์คํํ๋ค๊ณ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค. gunicorn์ด ํ์ค ์ถ๋ ฅ์ ๋ํ ์ก์ธ์ค ๋ ์ฝ๋๋ฅผ ๊ธฐ๋กํด์ผ ํฉ๋๊น? ๊ทธ๋ ๋ค๋ฉด gunicorn์ ๊ทธ๋ ๊ฒํ์ง ์์ต๋๋ค.
๋ช
๋ น์ค ์ธ์๊ฐ ์๋ https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L302 self.cfg.accesslog
๋ None
์ด๊ณ ํจ์๋ ์ผ์ฐ ๋ฐํ๋ฉ๋๋ค. ๋ด๊ฐ ๋งํ ์์๋ ํ --log-config
๋๋ --log-syslog
๋ฅผ ์ง์ ํ์ง ์๊ณ stdout์ ๋ก๊ทธ์ธํ๋ ๋ฐฉ๋ฒ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด ์ฌ๋ฐ๋ฅธ์ง?
์ด๊ฒ์ด ์๋ฏธํ๋ ๋ฐ๋ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ์ก์ธ์ค ๋ก๊ทธ๊ฐ ๋นํ์ฑํ๋์ด ์์ต๋๊น?
@benoitc ๋ค. ์์ ๋ ผ์๋ ์ก์ธ์ค ๋ก๊ทธ๊ฐ stdout์ผ๋ก ์ด๋ํ๊ณ ์ค๋ฅ ๋ก๊ทธ๊ฐ stderr๋ก ์ด๋ํจ์ ๋ํ๋ด๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋ฌ๋ ์ก์ธ์ค ๋ก๊น ์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋นํ์ฑํ๋์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
BTW, Python 2.7์ ์ฌ์ฉํ์ฌ --access-log /dev/stdout --error-log /dev/stderr
๋ฅผ ์ํํ ์ ์์๊ณ ์๋ํ ๊ฒ์
๋๋ค. Python 3์์ ์ธ์๋ก /dev/stdout
์ ๋ฌ ์คํจ
๐ @suriya ๋๋ ๋น์ ๊ณผ ๊ฐ์ ํ๋์ ์ฐพ๊ณ ์๋ค๊ณ ์๊ฐํฉ๋๋ค -- --capture-log
๋ฅผ ์คํํ๊ณ --access-logfile=<something>
$ ๋ฅผ ํ์ฑํํ๊ณ ์ถ์ง๋ง ์ก์ธ์ค ๋ก๊ทธ ๋ผ์ธ์ด stdout์ผ๋ก ์ด๋ํ๋ ๊ฒ์ ์ ํธํฉ๋๋ค ํ์ค ์ค๋ฅ๊ฐ ์๋๋๋ค.
ํธ์ง: ๋ช
ํํ ํ์๋ฉด ์ด๊ฒ์ Python3์ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค. python3.5.1์ ์ฌ์ฉํ์ฌ --access-logfile=/dev/stdout
๋ฅผ gunicorn์ ์ ๋ฌํ๋ฉด ์๋ฒ๊ฐ ์์๋์ง ์์ต๋๋ค.
์, ์ก์ธ์ค ๋ก๊น ์ด ๊ธฐ๋ณธ์ ์ผ๋ก ๋นํ์ฑํ๋์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
@huoxy ๊ธฐ๋ณธ๊ฐ๋ณด๋ค ๋ ๋ฌธ์ ๋ ํ์ค ์ถ๋ ฅ์ ์ก์ธ์ค ๋ก๊ทธ๋ฅผ ์ฐ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์๋ค๋ ๊ฒ์ ๋๋ค.
@huoxy ห--access-logfile=-`์ด ํธ๋ฆญ์ ์ํํด์ผ ํฉ๋๋ค. ์๋๋ผ๋ฉด ์๋ ค์ฃผ์ธ์.
@huoxy https://github.com/huoxy ๊ธฐ๋ณธ๊ฐ๋ณด๋ค ๋ ๋ง์ ๊ฒ ๊ฐ์์
๋ฌธ์ ๋ ์ก์ธ์ค ๋ก๊ทธ๋ฅผ ๊ธฐ๋กํ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์๋ค๋ ๊ฒ์ ๋๋ค.
ํ์ค ์ถ๋ ฅ.โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/benoitc/gunicorn/issues/1184#issuecomment -235501347,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/AAA4oj67GbLqwaJaCQ9NOH7-iAXJoMxGks5qZv9fgaJpZM4HHW4G
.
๋ํ ์๋ง๋ ๋ฌธ์ ๋ฌธ์ ์ผ ๊ฒ์
๋๋ค. ๊ทธ๋ฌ๋ ์ก์ธ์ค ๋ก๊ทธ๋ stdout์ ์ธ์๋์ด์ผ ํฉ๋๋ค.
-
๊ฐ ์ฌ์ฉ๋ ๋. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ฒ๊ทธ์
๋๋ค. ์๋ ค ์ค์...
2016๋
7์ 27์ผ ์์์ผ 09:03์ Benoit Chesneau [email protected] ์ด ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
@huoxy ห--access-logfile=-`์ด ํธ๋ฆญ์ ์ํํด์ผ ํฉ๋๋ค. ์๋๋ผ๋ฉด ์๋ ค์ฃผ์ธ์.
- ๋ฒ ๋์
2016๋ 7์ 27์ผ ์์์ผ 08:49 Suriya Subramanian [email protected]
์ผ๋ค:@huoxy https://github.com/huoxy ๊ธฐ๋ณธ๊ฐ๋ณด๋ค ๋ ๋ง์ ๊ฒ ๊ฐ์์
๋ฌธ์ ๋ ์ก์ธ์ค ๋ก๊ทธ๋ฅผ ๊ธฐ๋กํ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์๋ค๋ ๊ฒ์ ๋๋ค.
ํ์ค ์ถ๋ ฅ.โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/benoitc/gunicorn/issues/1184#issuecomment -235501347,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/AAA4oj67GbLqwaJaCQ9NOH7-iAXJoMxGks5qZv9fgaJpZM4HHW4G
.
@benoitc #1293์์ ์ธ๊ธํ๋ฏ์ด gunicorn --access-log -
๋ ํ์ค ์ค๋ฅ์ ๋ํ ์ก์ธ์ค๋ฅผ ๊ธฐ๋กํฉ๋๋ค. gunicorn --access-log=-
๋ก ์๋ํ์ง๋ง ๋ก๊ทธ๋ ์ฌ์ ํ ํ์ค ์ค๋ฅ๋ก ์ด๋ํฉ๋๋ค.
์ด์ ๋ฐ๋ฅด๋ฉด:
https://github.com/gunicorn/gunicorn/blob/master/gunicorn/glogging.py#L58
๊ธฐ๋ณธ ๋ก๊ฑฐ๋ stdout์ผ๋ก ์ถ๋ ฅ๋๋ console
์
๋๋ค. ๋ฐ๋ผ์ ์ ์ฒ๋ผ stdout์ ๋ชจ๋ ๊ฒ์ด ํ์ํ ๊ฒฝ์ฐ ๋ชจ๋ ๊ฒ์ด gunicorn ๋ก๊น
๋๋ผ์ด๋ฒ์ ๋๋ฌํ๊ธฐ ์ํด ํด๋น ์ต์
์ ๋น์ ๋ ์ ์์ต๋๋ค.
๋ํ ๋ด๊ฐ ์ ์ํ๋ ์๋ฃจ์
์ ์ง์ ์๋ํ์ง ์๋ ๊ฒฝ์ฐ /dev/stdout
๋๋ /dev/stderror
์ ๋ํ ๋ก๊ทธ ํ์ผ์ ๋ํ ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ง๋๋ ๊ฒ์
๋๋ค.
ln -sf /var/log/gunicorn.access.log /dev/stdout
ln -sf /var/log/gunicorn.error.log /dev/stdout
exec newrelic-admin run-program gunicorn --chdir /usr/src/app --name nexchange --bind 0.0.0.0:${GUNICORN_PORT} --workers 3 --log-level=info --log-file=/var/log/gunicorn.error.log --access-logfile=/var/log/gunicorn.access.log nexchange.wsgi:application "$@"
์ง๋์ฃผ์ ์ถ์๋ gunicorn 19.7.0์ผ๋ก ๋ฐฉ๊ธ ์ฎ๊ฒผ์ต๋๋ค. ๋ถํํ๋, ๋๋ ์ฌ์ ํ stderr ์ด์ธ์ ๋ค๋ฅธ ๊ฒ์ ๊ธฐ๋ก๋ ์ก์ธ์ค ๋ก๊ทธ๋ฅผ ์ป์ ์ ์์ต๋๋ค.
์ต์ ์์ด "--access-logfile=- --error-logfile=- --log-level=DEBUG"๋ฅผ ํฌํจํ๊ฑฐ๋ ํฌํจํ์ง ์๋ ๋ชจ๋ ์์ด์ ์ฌ์ฉํ์ฌ gunicorn์ ์คํํ๋ ค๊ณ ํ์ต๋๋ค.
gunicorn์ ๋ก๊น ์ ๋ํ ๊ธฐ๋ณธ์ ์ธ ๊ฒ์ ๋์น๊ณ ์์ต๋๊น? ๋ด ํ๊ฒฝ์ด๋ Django์ ๋ฌด์ธ๊ฐ๊ฐ ์ถํ์ ์ผ์ผ์ผ ์ด ๋ฌธ์ ๋ฅผ ์ผ์ผํฌ ์ ์์ต๋๊น?
์์ฉ ํ๋ก๊ทธ๋จ ํ์ผ myapp.py ๋ก ๋ค์์ ์๋ํ์ต๋๋ค.
$ python --version
Python 3.5.2
$ gunicorn --version
gunicorn (version 19.7.0)
$ gunicorn --access-logfile - myapp:app
์ก์ธ์ค ๋ก๊ทธ ์ถ๋ ฅ์ด stdout
๋ก ๊ฐ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
์ ๋ Python 2.7.14๋ฅผ ์ฌ์ฉ ์ค์ ๋๋ค. (๋ช ๋ฌ ์ ์ ๋น ๋ฅธ ์๋ต์ ๋์ณค์ต๋๋ค.)
gunicorn.config.py์์ accesslog = "-"
๋ฅผ ์ฌ์ฉํ ์๋ ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์์ฉ ํ๋ก๊ทธ๋จ ํ์ผ myapp.py ๋ก ๋ค์์ ์๋ํ์ต๋๋ค.
์ก์ธ์ค ๋ก๊ทธ ์ถ๋ ฅ์ด
stdout
๋ก ๊ฐ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.