4.8.1. Logging

According to "doc\NppExec\NppExec_TechInfo.txt", NppExec's logging can be enabled by specifying a 'LogsDir' parameter under the [Options] section of the "NppExec.ini".

The full path to the "NppExec.ini" configuration file can be obtained via

echo $(PLUGINS_CONFIG_DIR)

or even

npp_open $(PLUGINS_CONFIG_DIR)\NppExec.ini

To enable the logging, just add something similar to

LogsDir="NppExecLogs"

under the [Options] section of the "NppExec.ini".

Once it's done, restart Notepad++ and go to the folder "%TEMP%\NppExecLogs". It will contain a subfolder "NppExec" and a subfolder with the current date under it. You'll find the NppExec's log files there.

Here is a typical beginning of NppExec's log file:

22:00:17.618  7388  Log start >>
22:00:17.618  7388  ; CNppExec::ReadOptions - start
22:00:17.619  7388  ; CNppExec::ReadOptions - end
22:00:17.619  7388  ; CNppExecCommandExecutor - started
22:00:17.699  7388  ; NPPN_READY - start

The first column is the time in the format of hours:minutes:seconds.milliseconds. The second column is the thread identifier (NppExec uses different threads to perform different activities, such as processing GUI commands, running collateral scripts, etc).

Here is a typical ending of NppExec's log file:

22:01:26.454  7388  ; NPPN_SHUTDOWN - end
22:01:26.465  7388  ; CNppExecCommandExecutor: waiting for the ExecuteThreadDoneEvent...
22:01:26.465  7388  ; CNppExecCommandExecutor - stopped
22:01:26.467  7388  Log exit.

The absence of "Log exit." at the end of NppExec's log file (assuming Notepad++ had exited) would mean that either NppExec itself or Notepad++ in whole hung or crashed. Such crash or hang could be caused by some other Notepad++'s plugin or, in more rare cases, by NppExec or Notepad++ itself. If it was NppExec's fault, the last line of the log file at least shows the last successful activity before the hang or crash.

Note: NppExec's logger internally calls fflush() after each logged line. It may look excessive, but in case of a hang or a crash it helps to ensure that the log file does contain everything that could have been logged. So it would definitely help with the investigation.

In general, NppExec's logging is a great help when something goes wrong or does not go as it was expected. That is why there is a special command NPE_DEBUGLOG that enables NppExec's "logging" directly into NppExec's Console window. This command does not create an output log file (unless the 'LogsDir' parameter is specified in the "NppExec.ini") - instead it prints detailed information about each NppExec's command activity to NppExec's Console. This information is quite similar to what is (or would be) written to NppExec's log file, though NppExec's log file usually contains a little bit more information.

To enable this "debug logging", use

npe_debuglog on

or just

npe_debug 1

In this mode, NppExec also shows additional information when NppExec's hot-key is pressed and also when a line in NppExec's Console is double-clicked. The latter allows to "debug" the Console Highlight Filters - as it shows the matched filter (if any) for the double-clicked line.

Example:

  1. in Plugins -> NppExec -> Console Output Filters, specify e.g. "*error* : %FILE%" as one of the HighLight masks, check it to enable it, and press OK;
  2. type "echo Some error : Some file name" in NppExec's Console and press Enter;
  3. type "npe_debug 1" in NppExec's Console and press Enter;
  4. double-click the previously printed line "Some error : Some file name".

As the result, Notepad++ says that the file "Some file name" does not exist and proposes to create it. Obviously you don't need to create this file as it was just a test :) And here is what NppExec's Console shows:

; Console's line double-clicked
; WarningAnalyzer info
; {
;    Input line: "Some error : Some file name"
;    Match result: true
;    Active filter: "*error* : %FILE%"
;    * Parsed File Name: "Some file name"
;    * Parsed Line Number: <none>
;    * Parsed Char Position: <none>
; }