Community
    • Login

    .LOG updates

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 3 Posters 3.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Clemente RodriguezC
      Clemente Rodriguez
      last edited by

      windows NOTEPAD, writes DATE and TIME each time file is updated when includes .LOG like first line into a file.

      NOTEPAD++ would be nice to include it too, does not ?

      PeterJonesP 1 Reply Last reply Reply Quote 2
      • PeterJonesP
        PeterJones @Clemente Rodriguez
        last edited by PeterJones

        @Clemente-Rodriguez said in .LOG updates:

        windows NOTEPAD, writes DATE and TIME each time file is updated when includes .LOG like first line into a file.

        I had never heard of that feature. I knew that it had the F5 = Edit > Time/Date to manually insert it.

        NOTEPAD++ would be nice to include it too, does not ?

        personally, I don’t have a need for it, though I can see why some people might like it. If you were willing to install the PythonScript plugin, then it wouldn’t be too hard to come up with a script that could be automatically run when you start Notepad++; it would run a function every time a file was opened, and if it starts with .LOG as the first line, it would then append the date at the end of the file. If you’re not interested in using the PythonScript plugin, I won’t bother explaining the details, but if you’d like that, let us know, and I or one of the other PythonScript afficionados could probably hack it together in a reasonably short amount of time.

        rdipardoR PeterJonesP 2 Replies Last reply Reply Quote 2
        • rdipardoR
          rdipardo @PeterJones
          last edited by

          windows NOTEPAD, writes DATE and TIME each time file is updated when includes .LOG like first line into a file.

          It’s true!

          SQtbg.gif

          Looks like the timestamp is written upon opening the file (notice how the * appears immediately in the title bar), not when saving it.

          1 Reply Last reply Reply Quote 3
          • PeterJonesP
            PeterJones @PeterJones
            last edited by

            After I and @rdipardo had both separately confirmed that MS notepad.exe really does have that feature, I decided it was worth the effort to write the script, even if the original poster never comes back to ask for it.

            Installation instructions

            • see full instructions in our FAQ
              https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript
            • save the script below as DotLogTimestamp.py in the PythonScript user-scripts directory (usually %AppData%\Notepad++\Plugins\Config\PythonScript\Scripts\)
            • if you want this feature active every time you run Notepad++:
              1. Plugins > Python Script > Configuration: set Initialisation to ATSTARTUP
              2. As the FAQ mentions, add the following lines to the user startup.py
              import DotLogTimestamp
              _DLTS = DotLogTimestamp.DLTS()
              

            script: DotLogTimestamp.py

            # encoding=utf-8
            """in response to https://community.notepad-plus-plus.org/topic/24650/
            
            - Call this from startup.py using
            import DotLogTimestamp
            _DLTS = DotLogTimestamp.DLTS()
            
            - Make sure to set Plugins > PythonScript > Configuration > Initialisation to "ATSTARTUP" instead of "LAZY"
            
            - installation instructions: see
                https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript
            
            """
            from Npp import editor,notepad,console,NOTIFICATION
            from datetime import datetime
            
            class DLTS(object):
                def __init__(self):
                    console.write("Registered DotLogTimestamp.py callbacks\n")
                    notepad.callback(self.fileopened_callback, [NOTIFICATION.FILEOPENED])
                    notepad.callback(self.bufferactivated_callback, [NOTIFICATION.BUFFERACTIVATED])
                    self.active = True
                    self.bufferIDs = []
            
                def toggle(self):
                    self.active = not self.active
                    console.write("DotLogTimestamp.py callbacks are {}\n".format('active' if self.active else 'inactive'))
            
                def fileopened_callback(self, args):
                    if self.active:
                        self.bufferIDs.append(args['bufferID'])
            
                def bufferactivated_callback(self, args):
                    if self.active:
                        if args['bufferID'] in self.bufferIDs:
                            line = editor.getLine(0).strip()
                            if line[0:4] == ".LOG":
                                editor.appendText("{}\n".format(datetime.now().strftime("%Y-%b-%d %H:%M:%S")))
                            self.bufferIDs.remove(args['bufferID'])
            
            if __name__ == '__main__':
                try:
                    _DLTS.toggle()
                except NameError:
                    _DLTS = DLTS()
            
            1 Reply Last reply Reply Quote 6
            • PeterJonesP PeterJones referenced this topic on
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors