Merge lp:~nico44/joliebulle/logging into lp:joliebulle

Proposed by Nico
Status: Merged
Merged at revision: 300
Proposed branch: lp:~nico44/joliebulle/logging
Merge into: lp:joliebulle
Diff against target: 320 lines (+85/-20)
5 files modified
brewCalc.py (+4/-1)
globals.py (+12/-2)
main.py (+63/-15)
outilEvaporation.py (+3/-1)
preferences.py (+3/-1)
To merge this branch: bzr merge lp:~nico44/joliebulle/logging
Reviewer Review Type Date Requested Status
314r Pending
Review via email: mp+125044@code.launchpad.net

Description of the change

Ajout de l'utilisation de l'API logging.
Le logging est initialisé au démarrage. Le niveau et le format des traces est paramétrable dans la méthode initLogging(). Par défaut le niveau >=INFO apparait sur la console. Le niveau >=DEBUG apparait dans le fichier joliebulle.log

Pour l'utiliser dans un module il faut ajouter :
import logging
logger = logging.getLogger(__name__)

en début de fichier. Ensuite on peut utiliser logger.debug() logger.info(), logger.warn(), etc. comme décrit ici : http://docs.python.org/py3k/howto/logging.html#logging-from-multiple-modules

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'brewCalc.py'
2--- brewCalc.py 2012-09-04 22:31:19 +0000
3+++ brewCalc.py 2012-09-18 20:38:18 +0000
4@@ -25,6 +25,7 @@
5 import codecs
6 import PyQt4
7 import sys
8+import logging
9 from PyQt4 import QtGui
10 from PyQt4 import QtCore
11 from base import *
12@@ -33,6 +34,8 @@
13 from settings import *
14 from globals import *
15
16+logger = logging.getLogger(__name__)
17+
18
19 class CalcBrewday :
20
21@@ -85,7 +88,7 @@
22 self.infuseVol = 0
23 self.newRatio = ratio
24 else :
25- print('type non pris en charge')
26+ logger.warn('type non pris en charge')
27 # print('actualvol :', actualVol)
28 # print('ratio :', ratio)
29 # print('vm',Vm)
30
31=== modified file 'globals.py'
32--- globals.py 2012-09-17 19:38:40 +0000
33+++ globals.py 2012-09-18 20:38:18 +0000
34@@ -19,6 +19,12 @@
35
36 settings = Settings()
37
38+#Version Joliebulle à utiliser partout où nécessaire de l'afficher
39+# à modifier à chaque release pour :
40+# - retirer le '-DEV' au moment de la livraison
41+# - incrémenter le numéro de version et remettre le '-DEV' au commencement de la nouvelle itération
42+VERSION_JOLIBULLE = '2.8.0-DEV'
43+
44 if platform == 'win32':
45 home_dir = os.path.expanduser("~")
46 config_dir = os.path.join(os.path.expanduser("~"), "AppData", "Local", "joliebulle")
47@@ -36,9 +42,13 @@
48 config_dir = os.path.join(os.path.expanduser("~"), ".config", "joliebulle")
49 recettes_dir = settings.conf.value("pathUnix", os.path.join(os.path.expanduser("~"), ".config", "joliebulle", "recettes"))
50 database_file = os.path.join(os.path.expanduser("~"), ".config", "joliebulle", "database.xml")
51- database_root = os.path.join(os.environ['RESOURCEPATH'], "database.xml")
52+ if 'RESOURCEPATH' in os.environ:
53+ resourcePath = os.environ['RESOURCEPATH']
54+ else:
55+ resourcePath = os.getcwd()
56+ database_root = os.path.join(resourcePath, "database.xml")
57 mash_file = os.path.join(os.path.expanduser("~"), ".config", "joliebulle", "mash.xml")
58- mash_root = os.path.join(os.environ['RESOURCEPATH'], "mash.xml")
59+ mash_root = os.path.join(resourcePath, "mash.xml")
60 samples_dir='Samples'
61 samples_target = os.path.join(os.path.expanduser("~"), ".config", "joliebulle", "recettes", "Samples")
62
63
64=== modified file 'main.py' (properties changed: +x to -x)
65--- main.py 2012-09-18 19:52:34 +0000
66+++ main.py 2012-09-18 20:38:18 +0000
67@@ -25,6 +25,8 @@
68 import os
69 import os.path
70 import glob
71+import logging
72+import logging.config
73 from sys import platform
74 import PyQt4
75 import sys
76@@ -89,6 +91,40 @@
77 # painter.drawPixmap(option.rect.topLeft(), image)
78 # painter.restore()
79
80+def initLogging():
81+ config = {
82+ 'version': 1,
83+ 'root': {
84+ 'handlers': ['console','file'],
85+ 'level': 'DEBUG'
86+ },
87+ 'disable_existing_loggers': False,
88+ 'formatters': {
89+ 'standard': {
90+ 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
91+ },
92+ 'detailed': {
93+ 'format': '%(asctime)s %(module)-17s line:%(lineno)-4d %(levelname)-8s %(message)s'
94+ }
95+ },
96+ 'handlers': {
97+ 'console': {
98+ 'level':'INFO',
99+ 'class':'logging.StreamHandler',
100+ 'stream':'ext://sys.stdout',
101+ 'formatter':'standard'
102+ },
103+ 'file': {
104+ 'class':'logging.FileHandler',
105+ 'level':'DEBUG',
106+ 'formatter':'detailed',
107+ 'mode':'a',
108+ 'filename':os.path.join(config_dir,'joliebulle.log')
109+ }
110+ }
111+ }
112+ logging.config.dictConfig(config)
113+
114
115 class IngDelegate(QtGui.QItemDelegate):
116 def __init__(self, parent=None):
117@@ -807,8 +843,8 @@
118
119 argumentsList=QtGui.QApplication.arguments()
120 if len(argumentsList) > 1 :
121- print("la liste d'arguments:",argumentsList)
122- print("le chemin:",argumentsList[1])
123+ logger.debug("la liste d'arguments: %s",argumentsList)
124+ logger.debug("le chemin: %s",argumentsList[1])
125 # for part in argumentsList :
126 # recipePath=recipePath + " " + part
127 try:
128@@ -999,7 +1035,7 @@
129
130
131 if newName in newFileList :
132- print ('doublon !')
133+ logger.debug('doublon !')
134 sameCount= 0
135 while sameCount < len(newFileNameList) :
136 sameCount = sameCount+1
137@@ -1011,7 +1047,7 @@
138 break
139 else :
140 newFileList.append(newName)
141- print("new", newFileList)
142+ logger.debug(newFileList)
143
144 #on renomme
145 # k=0
146@@ -1186,7 +1222,7 @@
147 def initRep(self) :
148 home = QtCore.QDir(home_dir)
149 config = QtCore.QDir(config_dir)
150- print (config)
151+ logger.debug (config)
152 if not config.exists() :
153 home.mkpath (config_dir)
154 else :
155@@ -1253,7 +1289,7 @@
156
157
158 def switchToBrewday(self) :
159- print ("lock",self.brewdayLock)
160+ logger.debug ("lock %s",self.brewdayLock)
161 self.stackedWidget.setCurrentIndex(4)
162
163 if self.brewdayLock == 1 :
164@@ -1465,7 +1501,7 @@
165 self.dlgStepBrewday.setModal(True)
166 self.dlgStepBrewday.show()
167 self.dlgStepBrewday.setFields(self.brewdayCurrentStepTargetTemp, self.brewdayCurrentStepRatio, self.brewdayCurrentStepInfuseAmount, self.brewdayCurrentStepWaterTemp, self.grainWeight, self.stepsListVol, self.brewdayCurrentRow, self.brewdayListTemp, self.strikeTargetTemp)
168- print("envoyé !",self.brewdayCurrentStepTargetTemp,self.strikeTargetTemp )
169+ logger.debug("envoyé %s !",self.brewdayCurrentStepTargetTemp,self.strikeTargetTemp )
170
171 def purge (self) :
172 i = (AppWindow.nbreFer + AppWindow.nbreDivers + AppWindow.nbreHops + self.nbreLevures)
173@@ -1498,7 +1534,7 @@
174 self.calculs_recette()
175 self.MVC()
176
177- print (self.liste_fProportion)
178+ logger.debug(self.liste_fProportion)
179
180 def ajouterH(self) :
181
182@@ -1654,8 +1690,8 @@
183 pass
184 self.calculs_recette()
185 self.MVC()
186- print (self.liste_fProportion)
187- print ("index : " , indexLigne)
188+ logger.debug(self.liste_fProportion)
189+ logger.debug ("index : %s" , indexLigne)
190
191
192
193@@ -1966,7 +2002,7 @@
194
195 if self.mashName is not None :
196 self.currentMash={}
197- print('ouhouh !!!!!')
198+ logger.debug('ouhouh !!!!!')
199 self.currentMash['name'] = self.mashName
200 self.currentMash['ph'] = self.mashPh
201 self.currentMash['grainTemp'] = self.mashGrainTemp
202@@ -2018,7 +2054,7 @@
203 dicStep = listSteps[j-1]
204 dicStep['stepVol']= stepVol
205
206- print(self.currentMash)
207+ logger.debug(self.currentMash)
208 if self.mashName is not None :
209 self.mashProfilesBase.listMash.append(self.currentMash)
210 else :
211@@ -2510,7 +2546,6 @@
212 self.switchToEditor()
213 self.recipeNotes = self.textEditRecipeNotes.toPlainText()
214
215-
216 def recipeNotesRejected (self) :
217 self.switchToEditor()
218
219@@ -2528,7 +2563,6 @@
220 self.currentMash = self.mashProfilesBase.listMash[i]
221 self.tableWidgetStepsBrewday_currentRowChanged()
222
223-
224
225 def seeMash(self) :
226 self.switchToMash()
227@@ -2705,7 +2739,7 @@
228 self.popMashCombo()
229 self.switchToEditor()
230 self.comboBoxMashProfiles.setCurrentIndex(i)
231- print(self.currentMash)
232+ logger.debug(self.currentMash)
233
234 def saveProfile(self) :
235 self.mashProfileExport.export(self.listMash)
236@@ -2952,8 +2986,17 @@
237 self.webViewBiblio.print(printer)
238
239
240+
241 if __name__ == "__main__":
242
243+ initLogging()
244+
245+ logger = logging.getLogger(__name__)
246+
247+ logger.info("---------------------");
248+ logger.info("Jolibulle %s", VERSION_JOLIBULLE);
249+
250+ logger.debug("Initializing UI");
251 QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForName("utf-8"))
252 app = QtGui.QApplication(sys.argv)
253
254@@ -2970,4 +3013,9 @@
255 main_window = AppWindow()
256 main_window.show()
257
258+ logger.debug("UI initialized");
259+
260 app.exec_()
261+ logger.info("Joliebulle terminated");
262+ logger.info("---------------------");
263+
264
265=== modified file 'outilEvaporation.py'
266--- outilEvaporation.py 2012-09-04 22:31:19 +0000
267+++ outilEvaporation.py 2012-09-18 20:38:18 +0000
268@@ -23,10 +23,12 @@
269
270 import PyQt4
271 import sys
272+import logging
273 from PyQt4 import QtGui
274 from PyQt4 import QtCore
275 from outilEvaporation_ui import *
276
277+logger = logging.getLogger(__name__)
278
279
280 class DialogEvaporation(QtGui.QDialog):
281@@ -88,7 +90,7 @@
282 self.volPre = ((self.sgFinale * self.volFinal) + (self.volEvap * self.volRefroi)) / self.sgPre
283
284
285- print (self.volPre)
286+ logger.debug (self.volPre)
287
288
289
290
291=== modified file 'preferences.py'
292--- preferences.py 2012-09-04 22:31:19 +0000
293+++ preferences.py 2012-09-18 20:38:18 +0000
294@@ -25,6 +25,7 @@
295 import codecs
296 import PyQt4
297 import sys
298+import logging
299 from PyQt4 import QtGui
300 from PyQt4 import QtCore
301 from base import *
302@@ -35,6 +36,7 @@
303 import xml.etree.ElementTree as ET
304 from xml.dom import minidom
305
306+logger = logging.getLogger(__name__)
307
308
309 class DialogPref(QtGui.QDialog):
310@@ -88,7 +90,7 @@
311 settings.conf.setValue("pathWin32", self.ui.lineEditPathLib.text())
312 else :
313 settings.conf.setValue("pathUnix", self.ui.lineEditPathLib.text())
314- print (settings.conf.value("pathUnix"))
315+ logger.debug(settings.conf.value("pathUnix"))
316
317 settings.conf.setValue("BoilOffRate", self.ui.spinBoxBoilOff.value())
318 settings.conf.setValue("CoolingLoss", self.ui.spinBoxCooling.value())
319
320=== modified file 'setup.py' (properties changed: +x to -x)

Subscribers

People subscribed via source and target branches

to all changes: