Ich habe Probleme mit dem Python ‚Logging‘ Bibliothek der folgenden Fehler zu werfen:Python Logging-Modul Werfen Typeerror
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 861, in emit
msg = self.format(record)
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 734, in format
return fmt.format(record)
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 469, in format
s = self._fmt % record.__dict__
TypeError: not enough arguments for format string
Logged from file FILE_NAME.py, line 98
Stepping im Debugger der Aufzeichnung durch. dict hat alle erforderlichen Parameter für mein Format (siehe unten).
Dies trat auf, als ich änderte, wie meine Bootstrapping-Logik für die Bibliothek ausgeführt wird. Ich habe die Boartracking-Logik in eine Klasse verschoben (siehe unten) und rufe sie jetzt vom Start meiner Anwendung aus an.
class SetupLogging:
# Use class variable as 'singleton' to track if complete or not
_logging_bootstrap_complete = False
def bootstrap_logging(self):
if not SetupLogging._logging_bootstrap_complete:
logging.basicConfig(format='%(asctime)s [%s(filename)s:%(lineno)d] %(levelname)s: %(message)s',
level=logging.INFO, filename='FILE.log')
SetupLogging._logging_bootstrap_complete = True
Rufprotokollierung Bootstrap:
import Utilities
logger_boot = Utilities.SetupLogging()
logger_boot.bootstrap_logging()
Für das Leben von mir, dass ich nicht herausfinden kann, warum diese Änderung würde sehr geschätzt wird das Modul auf diese Weise und jede Hilfe auswirken würde.
Was 'nicht% s (Dateiname) s' zu tun? –
Doh. Das erste s soll nicht da sein. Das ist eigentlich die Antwort. Ich wünschte, ich könnte es so bezeichnen. –