##// END OF EJS Templates
log to file
José Chávez -
r1047:20a96cdbf240
parent child
Show More
@@ -8,7 +8,7 save_stdout = sys.stdout
8 sys.stdout = open('trash', 'w')
8 sys.stdout = open('trash', 'w')
9 from multiprocessing import cpu_count
9 from multiprocessing import cpu_count
10 from schaincli import templates
10 from schaincli import templates
11 from schainpy import controller_api
11 from schainpy.controller import Project
12 from schainpy.model import Operation, ProcessingUnit
12 from schainpy.model import Operation, ProcessingUnit
13 from schainpy.utils import log
13 from schainpy.utils import log
14 from importlib import import_module
14 from importlib import import_module
@@ -150,18 +150,8 def test():
150
150
151
151
152 def runFromXML(filename):
152 def runFromXML(filename):
153 controller = controller_api.ControllerThread()
153 controller = Project()
154 if not controller.readXml(filename):
154 if not controller.readXml(filename):
155 return
155 return
156
157 plotterObj = controller.useExternalPlotter()
158
159 controller.start()
156 controller.start()
160 plotterObj.start()
161
162 cliLogger("Finishing all processes")
163
164 controller.join(5)
165
166 cliLogger("End of script")
167 return
157 return
@@ -4,6 +4,12 Created on September , 2012
4 '''
4 '''
5
5
6 import sys
6 import sys
7
8 # save_stdout = sys.stdout
9 # logToFile = newLogger()
10 # sys.stdout = logToFile
11 # sys.stderr = logToFile
12
7 import ast
13 import ast
8 import datetime
14 import datetime
9 import traceback
15 import traceback
@@ -13,6 +19,7 from multiprocessing import Process, Queue, cpu_count
13
19
14 import schainpy
20 import schainpy
15 import schainpy.admin
21 import schainpy.admin
22 from schainpy.utils.log import logToFile
16
23
17 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
24 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
18 from xml.dom import minidom
25 from xml.dom import minidom
@@ -904,7 +911,6 class ReadUnitConf(ProcUnitConf):
904 self.endTime = opConfObj.getParameterValue('endTime')
911 self.endTime = opConfObj.getParameterValue('endTime')
905
912
906 class Project(Process):
913 class Project(Process):
907
908 id = None
914 id = None
909 name = None
915 name = None
910 description = None
916 description = None
@@ -916,16 +922,17 class Project(Process):
916
922
917 plotterQueue = None
923 plotterQueue = None
918
924
919 def __init__(self, plotter_queue=None):
925 def __init__(self, plotter_queue=None, logfile=None):
920 Process.__init__(self)
926 Process.__init__(self)
921 self.id = None
927 self.id = None
922 self.name = None
928 self.name = None
923 self.description = None
929 self.description = None
924
930 if logfile is not None:
931 logToFile(logfile)
925 self.plotterQueue = plotter_queue
932 self.plotterQueue = plotter_queue
926
933
927 self.procUnitConfObjDict = {}
934 self.procUnitConfObjDict = {}
928
935
929 def __getNewId(self):
936 def __getNewId(self):
930
937
931 idList = self.procUnitConfObjDict.keys()
938 idList = self.procUnitConfObjDict.keys()
@@ -1321,5 +1328,3 class Project(Process):
1321 for procKey in keyList:
1328 for procKey in keyList:
1322 procUnitConfObj = self.procUnitConfObjDict[procKey]
1329 procUnitConfObj = self.procUnitConfObjDict[procKey]
1323 procUnitConfObj.close()
1330 procUnitConfObj.close()
1324
1325 print "Process finished"
@@ -1,4 +1,4
1 """.
1 """
2 SCHAINPY - LOG
2 SCHAINPY - LOG
3 Simple helper for log standarization
3 Simple helper for log standarization
4 Usage:
4 Usage:
@@ -14,7 +14,8 SCHAINPY - LOG
14 [NEVER GONNA] - give you up
14 [NEVER GONNA] - give you up
15 with color red as background and white as foreground.
15 with color red as background and white as foreground.
16 """
16 """
17
17 import os
18 import sys
18 import click
19 import click
19
20
20 def warning(message):
21 def warning(message):
@@ -37,3 +38,22 def makelogger(topic, bg='reset', fg='reset'):
37 click.echo(click.style('[{}] - '.format(topic.upper()) + message,
38 click.echo(click.style('[{}] - '.format(topic.upper()) + message,
38 bg=bg, fg=fg))
39 bg=bg, fg=fg))
39 return func
40 return func
41
42 class LoggerForFile():
43 def __init__(self, filename):
44 self.old_stdout=sys.stdout
45 cwd = os.getcwd()
46 self.log_file = open(os.path.join(cwd, filename), 'w+')
47 def write(self, text):
48 text = text.rstrip()
49 if not text:
50 return
51 self.log_file.write(text + '\n')
52 self.old_stdout.write(text + '\n')
53 def flush(self):
54 self.old_stdout.flush()
55
56 def logToFile(filename='log.log'):
57 logger = LoggerForFile(filename)
58 sys.stdout = logger
59
General Comments 0
You need to be logged in to leave comments. Login now