File size: 1,480 Bytes
b55a977
 
9fa456d
 
b55a977
 
 
 
 
 
 
 
 
 
9fa456d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b55a977
9d377df
 
9fa456d
9d377df
 
 
 
 
b55a977
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import os
import logging
from logging.handlers import RotatingFileHandler

# UTF-8 인코딩 κ°•μ œ μ„€μ • (Windows cp949 였λ₯˜ λ°©μ§€)
if sys.platform == 'win32':
    sys.stdout.reconfigure(encoding='utf-8')
    sys.stderr.reconfigure(encoding='utf-8')

from app import create_app

app = create_app()

# λ‘œκΉ… μ„€μ •
if not app.debug:
    # ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œλŠ” 파일둜 λ‘œκΉ…
    if not os.path.exists('logs'):
        os.mkdir('logs')
    file_handler = RotatingFileHandler('logs/server.log', maxBytes=10240000, backupCount=10)
    file_handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
    ))
    file_handler.setLevel(logging.INFO)
    app.logger.addHandler(file_handler)
    app.logger.setLevel(logging.INFO)
    app.logger.info('μ„œλ²„ μ‹œμž‘')

# 디버그 λͺ¨λ“œμ—μ„œλ„ μ½˜μ†”μ— λͺ¨λ“  둜그 좜λ ₯
logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.StreamHandler(sys.stdout)
    ]
)

if __name__ == '__main__':
    try:
        print(f"[{__name__}] μ„œλ²„ μ‹œμž‘: http://0.0.0.0:5001")
        print(f"[{__name__}] λ‘œκ·ΈλŠ” μ½˜μ†”κ³Ό logs/server.log νŒŒμΌμ— κΈ°λ‘λ©λ‹ˆλ‹€.")
        app.run(host='0.0.0.0', port=5001, debug=True, use_reloader=False)
    except Exception as e:
        print(f"μ„œλ²„ μ‹œμž‘ 였λ₯˜: {e}")
        import traceback
        traceback.print_exc()