[Python-de] Loggen der Versionen eingebundener Module

Wagner, Frank F.Wagner at wika.de
Mo Dez 6 13:26:57 CET 2010


Hallo,

ich habe nach Peters Anleitung das Logging meiner Python Module implementiert und es funktionierte auch wie beabsichtigt. Allerding möchte ich die Ausgabe meiner Loggerei in einem Logfile festhalten. Also hab ich die Zeile der Konfiguration wie folgt umgeändert:

logging.basicConfig(filename="MODULVERSIONS.LOG", filemode="w",
                    level=logging.INFO, format=format)

Führe ich das Skript aus ist hinterher nirgends eine Datei "MODULVERSIONS.LOG" zu finden, es gibt aber auch keine Fehlermeldung bei der Ausführung.

Wo, wenn nicht im Verzeichnis des aufrufenden Skriptes würde denn die Logdatei geschrieben werden?

Mit freundlichen Grüßen / Kind regards

Frank Wagner
Entwicklung - Prozesstransmitter


WIKA 
Alexander Wiegand SE & Co. KG
Alexander Wiegand-Straße 30
63911 Klingenberg am Main

Tel: 09372-132-8995
Fax: 09372-132-9976
E-mail: f.wagner at wika.de

-----Ursprüngliche Nachricht-----
Von: python-de-bounces at python.net [mailto:python-de-bounces at python.net] Im Auftrag von Peter Hoffmann
Gesendet: Mittwoch, 1. Dezember 2010 18:06
An: Die Deutsche Python Mailingliste
Betreff: Re: [Python-de] Loggen der Versionen eingebundener Module

Hallo Frank,

die Version deiner Module sollte wie in PEP8[1] unter Version
Boookkeeping beschrieben in einer Variable __version__ stehen. Wenn
ihr Subversion oder CVS benutzt könnt ihr dafür Keyword Substitution
nehmen. Also einfach unter den Docstring folgendes einfügen:

"""barmodule.py docstring"""
 __version__ = "$Revision: 86849 $"

Um die Versionsnummern zu loggen würde ich das Standard python logging
Modul verwenden [3]. Dazu dann unter __version__ noch folgendes
schreiben:

    import logging
    version_logger = logging.getLogger('VERSION')
    version_logger.info(__version__)

Jetzt muss noch im Versuchsskript der logger konfiguriert und die
anderen Modul importiert werden:

    import logging
    format = "%(asctime)s - %(pathname)s %(name)s - %(message)s"
    logging.basicConfig(level=logging.INFO, format=format)
    import barmodule

Wenn du jetzt python bar.py aufrufst solltest du folgende Ausgabe bekommen:

    2010-12-01 18:01:16,260 - foo.py VERSION - 1.0.5
    2010-12-01 18:01:16,260 - /tmp/py/barmodule.py VERSION - 1.4.5

In der Konfiguration des Loggings kannst du die Ausgabe auch in eine
Datei umleiten.

Viele Grüße,
Peter


[1] http://www.python.org/dev/peps/pep-0008/
[2] http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html
[3] http://docs.python.org/library/logging.html

_______________________________________________
python-de maillist  -  python-de at python.net
http://python.net/mailman/listinfo/python-de

--
Bevor Sie diese E-Mail ausdrucken, überlegen Sie bitte, ob dies wirklich erforderlich ist. Please think before you print.
--
WIKA Alexander Wiegand SE & Co. KG
Alexander-Wiegand-Straße 30 - 63911 Klingenberg - Germany
Kommanditgesellschaft: Sitz Klingenberg - Amtsgericht Aschaffenburg HRA 1819
Komplementärin: WIKA Verwaltungs SE & Co. KG - Sitz Klingenberg -
Amtsgericht Aschaffenburg HRA 4685
Komplementärin: WIKA International SE - Sitz Klingenberg -
Amtsgericht Aschaffenburg HRB 10505
Vorstand: Alexander Wiegand
Vorsitzender des Aufsichtsrats: Dr. Max Egli
Telefon: (09372) 132-0
Internet: www.wika.com
-- 
The information contained in this E-Mail and any attached files are strictly confidential and may be subject to legal privilege. If you are not the intended recipient, his representative or the person responsible for delivering the message to the intended recipient, be advised that you have received this message in error and that any dissemination, copying or use of this message or attachment is strictly forbidden, as is the disclosure of the information therein. If you have received this E-Mail in error, please notify us immediately by E-Mail or telephone and delete this message and all its attachments subsequently. All reasonable precautions have been taken to ensure no viruses are present in this E-Mail.




Mehr Informationen über die Mailingliste python-de