Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Usually, the Windows Event Log doesn't store error messages in plain text, but rather message ID references and insertion strings.</p> <p>Instead of storing a message like <code>Service foo crashed unexpectedly</code>, it stores a message ID which points to a resource string stored in a DLL. In this case, the resource would be something like <code>Service %s crashed unexpectedly</code> and <code>foo</code> would be stored as insertion string. The program which writes the message registers the resource DLL.</p> <p>The reason for this is localization. DLLs can store lots of different resources (dialog layout, strings, icons…), and one DLL can contain the same resource in many different languages. The operating system automatically chooses the right resources depending on the system locale. Resource DLLs are used by virtually all Microsoft utilities and core utilities.</p> <p><sub>Side note: Nowadays, the preferred (and cross-platform) way for localization is <code>gettext</code>.</sub></p> <p>This is used for the message log as well – ideally, you could open a log from an German Windows installation on an English one with all messages in English.</p> <p>I suspect that the pywin32 implementation skips that mechanism by only having one single message ID (1) which is just something like <code>"%s"</code>. It is stored in <code>win32service.pyd</code> and registered by pywin32. This works fine as long as this file exists on the file system, but breaks as soon as it's hidden inside a PyInstaller executable. I guess you have to embed the message ID into your executable directly.</p> <p><strong>Edit:</strong> suspicion confirmed, the message table is indeed stored inside <code>win32service.pyd</code></p> <p><a href="http://media.leoluk.de/evlog_rh.png" rel="nofollow noreferrer">Resource Hacker showing the message table http://media.leoluk.de/evlog_rh.png</a></p> <p>Try to copy the message table resource from <code>win32service.pyd</code> to your PyInstaller executable (for example using <a href="http://media.leoluk.de/evlog_rh.png" rel="nofollow noreferrer">Resource Hacker</a>).</p> <p>Looking at the logging handler implementation, this might work:</p> <pre><code>def __init__(self, appname, dllname=None, logtype="Application"): logging.Handler.__init__(self) try: import win32evtlogutil, win32evtlog self.appname = appname self._welu = win32evtlogutil if not dllname: dllname = os.path.split(self._welu.__file__) dllname = os.path.split(dllname[0]) dllname = os.path.join(dllname[0], r'win32service.pyd') </code></pre> <p>You'd have to set <code>dllname</code> to <code>os.path.dirname(__file__)</code>. Use something like this if you want it to continue working for the unfrozen script:</p> <pre><code>if getattr(sys, 'frozen', False): dllname = None elif __file__: dllname = os.path.dirname(__file__) ntl = logging.handlers.NTEventLogHandler("Python Logging Test", dllname=dllname) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload