How to use Notepad++ to create a log file

The original Notepad of Microsoft Windows has a nice feature to create log files: Save a new file with the text .LOG as its first characters and a timestamp will be appended on subsequent openings.

Since my editor of choice nowadays is Notepad++ and I couldn’t find a similar solution for it (maybe I haven’t looked hard enough), I wrote one myself in the Python scripting language, with help of the plug-in PythonScript for Notepad++.

First, create two script files: and

Put them both either into %ProgramFiles(x86)%\Notepad++\plugins\PythonScript\scripts or %APPDATA%\Notepad++\plugins\config\PythonScript\scripts, depending on your setup of Notepad++.

Also, change the NPPPythonScript initialisation mode (Notepad++ -> Plugins -> Python Script -> Configuration -> Initialisation) from LAZY to ATSTARTUP.

That file contains the actual timestamp code and the notification callbacks, so that the script handles files that are opened when the text editor is already running.

Obviously, you can adjust the keyword and timestamp format to your own liking.

from Npp import *
import datetime

# To prevent that the same file gets be modified again while open, we'll keep an eye on all open .LOG files.
BufferIDList = set()

def updateLog (args):

	if editor.getCurLine().startswith(".LOG"):
		bid = notepad.getCurrentBufferID()
		if bid not in BufferIDList:
			# Move to the end of the document and append timestamp etc.
			editor.appendText("%s\n\n" %"%Y-%m-%d %H:%M:%S"))

def clearBufferIDList (args):
	except ValueError:

notepad.callback(clearBufferIDList, [NOTIFICATION.FILECLOSED])

# Tried FILEOPENED before, but had problems with it (wrong buffer getting updated, not updated at all or delayed...).
notepad.callback(updateLog, [NOTIFICATION.BUFFERACTIVATED])

This will handle the case that a .LOG file starts the program in the first place, and should look like this:

from Log import updateLog

And that’s it!
(Tested with Notepad++ 6.4.3 (Unicode) and Python Script