LogEx plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
mNo edit summary
 
(45 intermediate revisions by 2 users not shown)
Line 2: Line 2:


== Links ==
== Links ==
[[File:Exe.gif]] [] (77 KB)
<attach>LogEx.zip</attach>
 
[http://forums.winamp.com/showthread.php?s=&threadid=265680 LogEx thread on NSIS Discussion forum]


== Description ==
== Description ==
'''Version:''' 0.1.
'''Version:''' 0.9.1.


LogEx is a logging plugin.
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)
It allows to append a string to a logfile and show this string in the status listbox and/or the status bar (like DetailPrint)
'''Please note: NSIS v2.42 or higher is required for this plugin to run properly.'''


== How To Use ==
== How To Use ==
The most practical way to use this plugin is disabling the PluginUnload.
To do this call "SetPluginUnload alwaysoff" in all functions and sections where you use this plugin.
...


=== Init DLL Function ===
=== Init DLL Function ===


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


; FileName
; FileName
: Log file name. The file will be opened with FILE_APPEND_DATA, so evt. old data will be left untouched.
: Log file name.
: NOTE: The Init function will not create a directory when the path does not exist


=== Write DLL Function ===
=== Write DLL Function ===


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


; bWriteToStatusList  
; bWriteToStatusList  
Line 34: Line 36:
; 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
  LogEx::AddFile [ReadFromLine [ReadToLine]] Prefix FileName


; FileName
; ReadFromLine
: File to add to the logfile.
: Write from line <ReadFromLine> from the file to the logfile.
 
; ReadToLine
: Write to line <ReadToLine> from the file to the logfile.


; Prefix  
; Prefix  
: Prefix to add at the beginning of each new line.
: Prefix to add at the beginning of each new line.
; FileName
: File to add to the logfile.


=== Close DLL Function ===
=== Close DLL Function ===
Line 51: Line 62:
==Example==
==Example==


<highlight-nsis>LogEx::Init /NOUNLOAD "$TEMP\log.txt"
<highlight-nsis>LogEx::Init "$TEMP\log.txt"
LogEx::Write /NOUNLOAD "Write this line to the log file only"
LogEx::Write "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 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</highlight-nsis>
LogEx::Write 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 'Write complete "dir" output to the log file with "  >" as prefix'
LogEx::AddFile "  >" "$TEMP\output.log"
LogEx::Write 'Write "dir" output from line3 to the log file with "  " as prefix'
LogEx::AddFile 3 "  " "$TEMP\output.log"
LogEx::Write 'Write "dir" output from line3 to line6 to the log file with "  " as prefix'
LogEx::AddFile 3 6 "  " "$TEMP\output.log"
LogEx::Close
; Done</highlight-nsis>
 
Output C:\Documents and Settings\Admin\Local Settings\Temp\output.log:
<highlight-nsis>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</highlight-nsis>


== Notes ==
== Notes ==
Line 61: Line 117:
== 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 "bTruncateFile" 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
'''[version 0.3: 2007-02-16]'''
- Fixed bug in AddFile with empty file
'''[version 0.4: 2008-04-26]'''
- Removed newlines on ::Close
'''[version 0.5: 2008-10-08]'''
- Changed the Init function to open the log file in SHARE_READ mode
'''[version 0.6: 2008-11-28]'''
- Added Unicode support
'''[version 0.7: 2008-12-30]'''
- Now Unicode support is really working
- Used new NSIS 2.42 API lib
'''[version 0.7.1: 2008-12-31]'''
- Now using the PluginCallback function, so /NOUNLOAD is no longer required
'''[version 0.7.2: 2009-01-07]'''
- Relinked the Unicode Plugin version with the Unicode pluginapiU.lib
'''[version 0.8: 2009-03-30]'''
- "false" for boolean parameters is also processed now
'''[version 0.9: 2011-02-08]'''
- Using string_size plug-in function variable now, fixed extra NULL char in Unicode
'''[version 0.9.1: 2011-06-20]'''
- Fixed possible stack corruption in Write function
- Added check for valid hFile in AddFile function


JP de Ruiter
JP de Ruiter
[http://www.deruiter.jp/index.php?page=LogEx&sub=Projects http://www.deruiter.jp]


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

Latest revision as of 18:52, 20 June 2011

Author: jpderuiter (talk, contrib)


Links

LogEx.zip (67 KB)

LogEx thread on NSIS Discussion forum

Description

Version: 0.9.1.

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)

Please note: NSIS v2.42 or higher is required for this plugin to run properly.

How To Use

Init DLL Function

LogEx::Init [bTruncateFile] FileName
bTruncateFile
If true, truncate file, else append to existing file.
FileName
Log file name.
NOTE: The Init function will not create a directory when the path does not exist

Write DLL Function

LogEx::Write [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 [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 "$TEMP\log.txt"
LogEx::Write "Write this line to the log file only"
LogEx::Write true "Write this line to the log file and the status list box"
LogEx::Write 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 'Write complete "dir" output to the log file with "   >" as prefix'
LogEx::AddFile "   >" "$TEMP\output.log"
LogEx::Write 'Write "dir" output from line3 to the log file with "   " as prefix'
LogEx::AddFile 3 "   " "$TEMP\output.log"
LogEx::Write 'Write "dir" output from line3 to line6 to the log file with "   " as prefix'
LogEx::AddFile 3 6 "   " "$TEMP\output.log"
LogEx::Close
; Done

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

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 "bTruncateFile" 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

[version 0.3: 2007-02-16]

- Fixed bug in AddFile with empty file

[version 0.4: 2008-04-26]

- Removed newlines on ::Close

[version 0.5: 2008-10-08]

- Changed the Init function to open the log file in SHARE_READ mode

[version 0.6: 2008-11-28]

- Added Unicode support

[version 0.7: 2008-12-30]

- Now Unicode support is really working
- Used new NSIS 2.42 API lib

[version 0.7.1: 2008-12-31]

- Now using the PluginCallback function, so /NOUNLOAD is no longer required

[version 0.7.2: 2009-01-07]

- Relinked the Unicode Plugin version with the Unicode pluginapiU.lib

[version 0.8: 2009-03-30]

- "false" for boolean parameters is also processed now

[version 0.9: 2011-02-08]

- Using string_size plug-in function variable now, fixed extra NULL char in Unicode

[version 0.9.1: 2011-06-20]

- Fixed possible stack corruption in Write function
- Added check for valid hFile in AddFile function

JP de Ruiter

http://www.deruiter.jp