Commit d91a4c2b4d08aff2fe7c07e5e07b097ea4f05f8f

Authored by Jeremy
1 parent 61e60444
Exists in master and in 1 other branch dev

Inserted logger

logs/Readme.md 0 โ†’ 100644
... ... @@ -0,0 +1,24 @@
  1 +File Logs are organized by module
  2 +
  3 +For example, logs for the module MONITORING must be in the file :
  4 +
  5 +> monitoring.logs
  6 +
  7 +The logs are formated like this :
  8 +
  9 +> '%(filename)s : %(lineno)s -> %(message)s'
  10 +> "filename : line -> message".
  11 +
  12 +To use the logger you must import logger.config
  13 +
  14 +> import logger.config as l
  15 +> log = l.setupLogger("name", "file_name")
  16 +
  17 +Basic log :
  18 +
  19 +> log.info('Your message')
  20 +
  21 +if you want to log in the file pyros.log you must use logging
  22 +
  23 +> import logger.config as l
  24 +> l.logging.info('Your message')
... ...
logs/pyros.log 0 โ†’ 100644
... ... @@ -0,0 +1,13 @@
  1 +config-
  2 +config -> Logger instantiated
  3 +config -> Logger instantiated
  4 +config -> Logger instantiated
  5 +config -> Logger instantiated
  6 +config -> Logger instantiated
  7 +config -> Logger instantiated
  8 +config -> Logger instantiated
  9 +2016-10-27 15:17:43,031 : config -> Logger instantiated
  10 +2016-10-27 15:17:52,770 : config -> Logger instantiated
  11 +2016-10-27 15:18:03,562 : config -> Logger instantiated
  12 +2016-10-27 15:18:18,357 : config -> Logger instantiated
  13 +2016-10-27 15:18:25,094 : config -> Logger instantiated
... ...
logs/routine_manager-views.log 0 โ†’ 100644
pyrosrun.sh
... ... @@ -10,7 +10,8 @@ COMMANDS="\n
10 10 \t'simul_on' : Starts the simulators\n
11 11 \t'simul_off' : Stops the simulators\n
12 12 \t'start' : Starts the simulators then the celery workers, then the web server\n
13   -\t'stop' : Stops the celery workers then the simulators"
  13 +\t'stop' : Stops the celery workers then the simulators\n
  14 +\t'clear_logs' : Clear all pyros .log files from /logs"
14 15  
15 16 NEEDED_COMMAND="One command is needed. Possible commands : $COMMANDS"
16 17 INVALID_COMMAND="Invalid command. Possible commands : $COMMANDS"
... ... @@ -74,6 +75,11 @@ case "$1" in
74 75 ./kill_all.sh
75 76 cd -
76 77 ;;
  78 + "clear_logs")
  79 + cd ../logs
  80 + rm -f *.log
  81 + cd -
  82 + ;;
77 83 *)
78 84 echo -e $INVALID_COMMAND
79 85 ;;
... ...
src/logger/__init__.py 0 โ†’ 100644
src/logger/config.py 0 โ†’ 100644
... ... @@ -0,0 +1,25 @@
  1 +from django.conf import settings
  2 +import logging
  3 +import sys
  4 +
  5 +# maybe reset files with a variable from settings for the logging
  6 +# if (settings.RESETLOGS):
  7 +
  8 +
  9 +logging.basicConfig(filename='%s/../logs/pyros.log'%(settings.BASE_DIR), format='%(asctime)s : %(module)s -> %(message)s', level=logging.DEBUG)
  10 +
  11 +if (settings.DEBUG):
  12 + logging.info('Logger instantiated')
  13 +
  14 +def setupLogger(logger_name, log_file, level=logging.INFO):
  15 + l = logging.getLogger(logger_name)
  16 + formatter = logging.Formatter('%(filename)s : %(lineno)s -> %(message)s')
  17 + fileHandler = logging.FileHandler('%s/../logs/%s.log'%(settings.BASE_DIR, log_file), mode='w')
  18 + fileHandler.setFormatter(formatter)
  19 + # streamHandler = logging.StreamHandler()
  20 + # streamHandler.setFormatter(formatter)
  21 +
  22 + l.setLevel(level)
  23 + l.addHandler(fileHandler)
  24 + # l.addHandler(streamHandler)
  25 + return (logging.getLogger(logger_name))
... ...
src/routine_manager/views.py
... ... @@ -7,6 +7,11 @@ from .validators import check_plan_validity, check_album_validity, check_sequenc
7 7 from .RequestSerializer import RequestSerializer
8 8 import scheduler
9 9  
  10 +""" logger """
  11 +from django.conf import settings
  12 +import logger.config as l
  13 +log = l.setupLogger("l1", "routine_manager-views")
  14 +
10 15 """ XML Export / Import utils """
11 16 from wsgiref.util import FileWrapper
12 17 from django.utils.encoding import smart_str
... ... @@ -24,6 +29,9 @@ def requests_list(request, status=0, message=""):
24 29 Retrieves and display the routines list (routine manager main page)
25 30 """
26 31  
  32 + if settings.DEBUG:
  33 + log.info("From requests_list")
  34 +
27 35 if status == "-1":
28 36 error = True
29 37 elif status == "1":
... ... @@ -54,6 +62,9 @@ def action_request(request, req_id, action, status=0, message=""):
54 62 req = Request.objects.get(id=req_id)
55 63 depth_level = 1
56 64  
  65 + if settings.DEBUG:
  66 + log.info("From action_request")
  67 +
57 68 if status == "-1":
58 69 error = True
59 70 elif status == "1":
... ... @@ -91,6 +102,9 @@ def request_validate(request, req_id):
91 102 req = Request.objects.get(id=req_id)
92 103 form = RequestForm(instance=req, data=request.POST)
93 104  
  105 + if (settings.DEBUG):
  106 + log.info("From request_validate")
  107 +
94 108 if action == "cancel":
95 109 if req.name == "New request":
96 110 req.delete()
... ... @@ -123,6 +137,9 @@ def action_sequence(request, seq_id, action, status=0, message=""):
123 137 req_id = req.id
124 138 depth_level = 2
125 139  
  140 + if (settings.DEBUG):
  141 + log.info("From action_sequence")
  142 +
126 143 if status == "-1":
127 144 error = True
128 145 elif status == "1":
... ... @@ -158,6 +175,9 @@ def sequence_validate(request, seq_id):
158 175 Possible actions : Cancel, Save, Save and add album, Delete
159 176 """
160 177  
  178 + if (settings.DEBUG):
  179 + log.info("From sequence_validate")
  180 +
161 181 seq_id = int(seq_id)
162 182 action = request.POST.get("action")
163 183 seq = Sequence.objects.get(id=seq_id)
... ... @@ -197,6 +217,9 @@ def action_album(request, alb_id, action, status=0, message=""):
197 217 seq_id = alb.sequence.id
198 218 depth_level = 3
199 219  
  220 + if (settings.DEBUG):
  221 + log.info("From action_album")
  222 +
200 223 if status == "-1":
201 224 error = True
202 225 elif status == "1":
... ... @@ -235,6 +258,10 @@ def album_validate(request, alb_id):
235 258 alb = Album.objects.get(id=alb_id)
236 259 form = AlbumForm(instance=alb, data=request.POST)
237 260  
  261 + if (settings.DEBUG):
  262 + log.info("From album_validate")
  263 +
  264 +
238 265 if action == "cancel":
239 266 if alb.name == "New album":
240 267 alb.delete()
... ... @@ -272,6 +299,9 @@ def action_plan(request, plan_id, action, status=0, message=""):
272 299 alb_id = plan.album.id
273 300 depth_level = 4
274 301  
  302 + if (settings.DEBUG):
  303 + log.info("From action_plan")
  304 +
275 305 if status == "-1":
276 306 error = True
277 307 elif status == "1":
... ... @@ -310,6 +340,10 @@ def plan_validate(request, plan_id):
310 340 plan = Plan.objects.get(id=plan_id)
311 341 form = PlanForm(instance=plan, data=request.POST)
312 342  
  343 + if (settings.DEBUG):
  344 + log.info("From plan_validate")
  345 +
  346 +
313 347 if action == "cancel":
314 348 if plan.name == "New plan":
315 349 plan.delete()
... ... @@ -376,6 +410,9 @@ def submit_request(request, req_id, redir):
376 410 Submits a request and its sequences for scheduling
377 411 """
378 412  
  413 + if (settings.DEBUG):
  414 + log.info("From submit_request")
  415 +
379 416 req = Request.objects.get(id=req_id)
380 417 error = False
381 418 if req.complete == False:
... ... @@ -409,6 +446,9 @@ def unsubmit_request(request, req_id):
409 446 Unsubmits a request and remove its sequences from scheduling
410 447 """
411 448  
  449 + if (settings.DEBUG):
  450 + log.info("From unsubmit_request")
  451 +
412 452 req = Request.objects.get(id=req_id)
413 453  
414 454 # TODO: uncomment pour la production
... ... @@ -438,6 +478,9 @@ def export_request(request, req_id):
438 478 Create an XML file with the given request, and send a download request to the user
439 479 """
440 480  
  481 + if (settings.DEBUG):
  482 + log.info("From export_request")
  483 +
441 484 req = Request.objects.get(id=req_id)
442 485 if req.complete == False:
443 486 message = "Request must be completely valid to be serialized"
... ... @@ -463,6 +506,9 @@ def import_request(request):
463 506 Don't do anything if there is a single error into the file
464 507 """
465 508  
  509 + if (settings.DEBUG):
  510 + log.info("From import_request")
  511 +
466 512 if request.method == "POST":
467 513 file = request.FILES.get("request_file")
468 514 if file is None:
... ...