Commit e675c756dd91168ccd7ccb83452568e57e2f254f
1 parent
712961ef
Exists in
devel
[TranslationServer] Adiciona server para escrita de log em arquivo
Showing
1 changed file
with
16 additions
and
2 deletions
Show diff stats
src/TranslationServer.py
... | ... | @@ -6,7 +6,8 @@ from functools import wraps |
6 | 6 | from PortGlosa import traduzir |
7 | 7 | from subprocess import check_output |
8 | 8 | from threading import Lock |
9 | -import os, argparse, thread | |
9 | +from logging.handlers import RotatingFileHandler | |
10 | +import os, argparse, thread, logging, sys | |
10 | 11 | |
11 | 12 | RUN_MODE=None |
12 | 13 | BUNDLES_PATH=None |
... | ... | @@ -42,9 +43,21 @@ def full_mode(): |
42 | 43 | conn = MySQLdb.connect(user="root", db="signsdb") |
43 | 44 | check_database() |
44 | 45 | |
46 | +def logger(): | |
47 | + global app | |
48 | + logfile = os.path.join(os.environ['HOME'], "translate.log") | |
49 | + print ' * Running...\n # See the log in: ' + logfile | |
50 | + handler = RotatingFileHandler(logfile, maxBytes=10000, backupCount=10) | |
51 | + handler.setLevel(logging.DEBUG) | |
52 | + app.logger.addHandler(handler) | |
53 | + log = logging.getLogger('werkzeug') | |
54 | + log.setLevel(logging.DEBUG) | |
55 | + log.addHandler(handler) | |
56 | + | |
45 | 57 | def init_mode(args): |
46 | 58 | global RUN_MODE |
47 | - RUN_MODE = args.mode.lower() | |
59 | + if args.logfile: logger() | |
60 | + RUN_MODE = args.mode.upper() | |
48 | 61 | if RUN_MODE == "dict": |
49 | 62 | dict_mode() |
50 | 63 | print "# Server started in dictionary mode. Requests will be accepted for translation of texts and download bundles.\n# Endpoints '/translate' and '/<PLATFORM>/<SIGN>' are available." |
... | ... | @@ -183,6 +196,7 @@ if __name__ == "__main__": |
183 | 196 | parser = argparse.ArgumentParser(description='Translation server and signs download for VLibras.') |
184 | 197 | parser.add_argument('--port', help='Port where the server will be available.', default=3000) |
185 | 198 | parser.add_argument("--mode", help="So that the server will work.", choices=['translate','dict','full'], default="translate") |
199 | + parser.add_argument("--logfile", action="store_true", help="So that the server will work.") | |
186 | 200 | args = parser.parse_args() |
187 | 201 | init_mode(args) |
188 | 202 | app.run(host="0.0.0.0", port=int(args.port), threaded=True, debug=False) |
189 | 203 | \ No newline at end of file | ... | ... |