LogEx plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 7: Line 7:


== Description ==
== Description ==
'''Version:''' 0.1.
'''Version:''' 0.2.


LogEx is a logging plugin.
LogEx is a logging plugin.
Line 16: Line 16:
=== Init DLL Function ===
=== Init DLL Function ===


  LogEx::Init /NOUNLOAD FileName
  LogEx::Init /NOUNLOAD [bAppendToFile] FileName
 
; bAppendToFile
: If true, append to existing file, else truncate file.


; FileName
; FileName
Line 23: Line 26:
=== Write DLL Function ===
=== Write DLL Function ===


  LogEx::Write /NOUNLOAD LogString [bWriteToStatusList] [bWriteToStatusBar]
  LogEx::Write /NOUNLOAD [bWriteToStatusList [bWriteToStatusBar]] LogString
 
; LogString  
: String to write to the logfile.


; bWriteToStatusList  
; bWriteToStatusList  
Line 33: Line 33:
; bWriteToStatusBar  
; bWriteToStatusBar  
: If equal to true, adds the string to the Status Bar.
: If equal to true, adds the string to the Status Bar.
; LogString
: String to write to the logfile.


=== AddFile DLL Function ===
=== AddFile DLL Function ===


  LogEx::AddFile /NOUNLOAD FileName Prefix [ReadFromLine] [ReadToLine]
  LogEx::AddFile /NOUNLOAD [ReadFromLine [ReadToLine]] Prefix FileName
 
; FileName  
: File to add to the logfile.
 
; Prefix
: Prefix to add at the beginning of each new line.


; ReadFromLine
; ReadFromLine
Line 49: Line 46:
; ReadToLine
; ReadToLine
: Write to line <ReadToLine> from the file to the logfile.
: Write to line <ReadToLine> from the file to the logfile.
; Prefix
: Prefix to add at the beginning of each new line.
; FileName
: File to add to the logfile.


=== Close DLL Function ===
=== Close DLL Function ===
Line 58: Line 61:
<highlight-nsis>LogEx::Init /NOUNLOAD "$TEMP\log.txt"
<highlight-nsis>LogEx::Init /NOUNLOAD "$TEMP\log.txt"
LogEx::Write /NOUNLOAD "Write this line to the log file only"
LogEx::Write /NOUNLOAD "Write this line to the log file only"
LogEx::Write /NOUNLOAD "Write this line to the log file and the status list box" true
LogEx::Write /NOUNLOAD true "Write this line to the log file and the status list box"
LogEx::Write /NOUNLOAD "Write this line to the log file, the status list box and the statusbar" true true
LogEx::Write /NOUNLOAD true true "Write this line to the log file, the status list box and the statusbar"
LogEx::Write /NOUNLOAD 'Write complete "dir" output to the log file with ">" as prefix'
 
ExecDos::exec 'cmd /C dir' "" "$TEMP\output.log"
ExecDos::exec 'cmd /C dir' "" "$TEMP\output.log"
LogEx::AddFile /NOUNLOAD "$TEMP\output.log" ">"
 
LogEx::Write /NOUNLOAD 'Write "dir" output from line3 to the log file'
LogEx::Write /NOUNLOAD 'Write complete "dir" output to the log file with "  >" as prefix'
ExecDos::exec 'cmd /C dir' "" "$TEMP\output.log"
LogEx::AddFile /NOUNLOAD "  >" "$TEMP\output.log"
LogEx::AddFile /NOUNLOAD "$TEMP\output.log" "" 3
LogEx::Write /NOUNLOAD 'Write "dir" output from line3 to the log file with "   " as prefix'
LogEx::Write /NOUNLOAD 'Write "dir" output from line3 to line6 to the log file'
LogEx::AddFile /NOUNLOAD 3 "  " "$TEMP\output.log"
ExecDos::exec 'cmd /C dir' "" "$TEMP\output.log"
LogEx::Write /NOUNLOAD 'Write "dir" output from line3 to line6 to the log file with "  " as prefix''
LogEx::AddFile /NOUNLOAD "$TEMP\output.log" "" 3 6
LogEx::AddFile /NOUNLOAD 3 6 "  " "$TEMP\output.log"
LogEx::Close
LogEx::Close
; Done</highlight-nsis>
; Done</highlight-nsis>
Line 111: Line 114:
== Version History ==
== Version History ==
'''[version 0.1: 2007-02-12]'''
'''[version 0.1: 2007-02-12]'''
Initial version.
- Initial version.
'''[version 0.2: 2007-02-16]'''
- Fixed stack bug.
- Added parameter "bAppendToFile" to Init function
- Changed the way AddFile function reads the file (read the file at ones in a buffer allocated with VirtualAlloc)
- Added comments in sourcecode


JP de Ruiter
JP de Ruiter


[[Category:Plugins]]
[[Category:Plugins]]

Revision as of 22:38, 16 February 2007

Author: jpderuiter (talk, contrib)


Links

LogEx.zip (67 KB)

LogEx thread on NSIS Discusion forum

Description

Version: 0.2.

LogEx is a logging plugin. It allows to append a string to a logfile and show this string in the status listbox and/or the status bar (like DetailPrint)

How To Use

Init DLL Function

LogEx::Init /NOUNLOAD [bAppendToFile] FileName
bAppendToFile
If true, append to existing file, else truncate file.
FileName
Log file name. The file will be opened with FILE_APPEND_DATA, so evt. old data will be left untouched.

Write DLL Function

LogEx::Write /NOUNLOAD [bWriteToStatusList [bWriteToStatusBar]] LogString
bWriteToStatusList
If equal to true, adds the string to the Status Listbox.
bWriteToStatusBar
If equal to true, adds the string to the Status Bar.
LogString
String to write to the logfile.

AddFile DLL Function

LogEx::AddFile /NOUNLOAD [ReadFromLine [ReadToLine]] Prefix FileName
ReadFromLine
Write from line <ReadFromLine> from the file to the logfile.
ReadToLine
Write to line <ReadToLine> from the file to the logfile.
Prefix
Prefix to add at the beginning of each new line.
FileName
File to add to the logfile.

Close DLL Function

LogEx::Close

Example

LogEx::Init /NOUNLOAD "$TEMP\log.txt"
LogEx::Write /NOUNLOAD "Write this line to the log file only"
LogEx::Write /NOUNLOAD true "Write this line to the log file and the status list box"
LogEx::Write /NOUNLOAD true true "Write this line to the log file, the status list box and the statusbar"
 
ExecDos::exec 'cmd /C dir' "" "$TEMP\output.log"
 
LogEx::Write /NOUNLOAD 'Write complete "dir" output to the log file with "   >" as prefix'
LogEx::AddFile /NOUNLOAD "   >" "$TEMP\output.log"
LogEx::Write /NOUNLOAD 'Write "dir" output from line3 to the log file with "   " as prefix'
LogEx::AddFile /NOUNLOAD 3 "   " "$TEMP\output.log"
LogEx::Write /NOUNLOAD 'Write "dir" output from line3 to line6 to the log file with "   " as prefix''
LogEx::AddFile /NOUNLOAD 3 6 "   " "$TEMP\output.log"
LogEx::Close
; Done

Output C:\Documents and Settings\Admin\Local Settings\Temp\log.txt:

Write this line to the log file only
Write this line to the log file and the status list box
Write this line to the log file, the status list box and the statusbar
Write complete "dir" output to the log file with "   >" as prefix
   > Volume in drive C has no label.
   > Volume Serial Number is xxxx-xxxx
   > Directory of C:\
   >07-11-2006  18:06                 0 AUTOEXEC.BAT
   >07-11-2006  18:06                 0 CONFIG.SYS
   >01-02-2007  03:17    <DIR>          Documents and Settings
   >11-02-2007  13:50    <DIR>          Program Files
   >20-01-2007  09:06    <DIR>          SYSTEMTOOLS
   >07-02-2007  17:27    <DIR>          temp
   >12-02-2007  23:48    <DIR>          WINDOWS
   >               2 File(s)           78.807 bytes
   >               5 Dir(s)  33.130.020.864 bytes free
Write "dir" output from line3 to the log file with "   " as prefix
    Directory of C:\
   07-11-2006  18:06                 0 AUTOEXEC.BAT
   07-11-2006  18:06                 0 CONFIG.SYS
   01-02-2007  03:17    <DIR>          Documents and Settings
   11-02-2007  13:50    <DIR>          Program Files
   20-01-2007  09:06    <DIR>          SYSTEMTOOLS
   07-02-2007  17:27    <DIR>          temp
   12-02-2007  23:48    <DIR>          WINDOWS
                  2 File(s)           78.807 bytes
                  5 Dir(s)  33.130.020.864 bytes free
Write "dir" output from line3 to line6 to the log file with "   " as prefix
    Directory of C:\
   07-11-2006  18:06                 0 AUTOEXEC.BAT
   07-11-2006  18:06                 0 CONFIG.SYS
   01-02-2007  03:17    <DIR>          Documents and Settings

Notes

The LogEx::AddFile function is especially usefull in combination with execution of a console application (like ExecDos plug-in)

Version History

[version 0.1: 2007-02-12]

- Initial version.

[version 0.2: 2007-02-16]

- Fixed stack bug.
- Added parameter "bAppendToFile" to Init function
- Changed the way AddFile function reads the file (read the file at ones in a buffer allocated with VirtualAlloc)
- Added comments in sourcecode

JP de Ruiter