Jump to content
Sign in to follow this  
foolet

Choose/Display Log file in real time

Recommended Posts

foolet

I keep trying and trying but I keep failing... I was hoping someone could help me with this I need to make a autoit script that basically let's you choose a log file then displays its contents in real time in a dos box.

Share this post


Link to post
Share on other sites
Xenobiologist

You mean reading a file displaying its content and then updating the content in a loop e.g. every 10 ms ?


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
UEZ

Try this:

;Coded by UEZ Build 2010-06-30, thanks to KaFu for the hint ;-)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)

Global $iMemo, $new_line
$width = 1024
$height = 600
$hGUI = GUICreate("Realtime Log Reader by UEZ 2010", $width, $height, -1, -1, Default, $WS_EX_TOPMOST)
$iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY)
GUICtrlSetLimit(-1, 0x7FFFFFFF)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then
    $file = $CmdLine[1]
Else
    $file = @WindowsDir & "\WindowsUpdate.log"
EndIf
$hFile = FileOpen($file)
$txt = FileRead($hFile)

GUICtrlSetData($iMemo, $txt, 1)
_GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff)
$cl = _FileCountLines($file)
$fs = FileGetSize($file)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(1000)
    $fs_new = FileGetSize($file)
    If $fs < $fs_new Then
        $cl_new = _FileCountLines($file)
        For $i = $cl + 1 To $cl_new
            $new_line &= FileReadLine($hFile, $i) & @CRLF
        Next
        GUICtrlSetData($iMemo, $new_line, 1)
;~      _GUICtrlEdit_LineScroll($iMemo, 0, 0xfffffff)
        $cl = $cl_new
        $fs = $fs_new
        $new_line = ""
    EndIf
Wend

Func _Exit()
    FileClose($hFile)
    GUIDelete($hGUI)
    Exit
EndFunc

It will read the WindowsUpdate.log and display it. If you run wuauclt /detectnow the log file will be updated and displayed in the GUI.

I don't know whether it will work properly... If not please report!

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
foolet

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)

Global $iMemo, $new_line
$width = 1024
$height = 800
$hGUI = GUICreate("Test", $width, $height, -1, -1, Default, $WS_EX_TOPMOST)
$iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY)
GUICtrlSetLimit(-1, 0x7FFFFFFF)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")

$file = @WindowsDir & "\WindowsUpdate.log"
$hFile = FileOpen($file)

$txt = FileRead($file)
MemoWrite($txt)
ControlSend($hGui, "", $iMemo, "{DOWN}")
_GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff)
$cl = _FileCountLines($file)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While 1
    $cl_new = _FileCountLines($file)
    If $cl < $cl_new Then
        For $i = $cl + 1 To $cl_new
            $new_line &= FileReadLine($hFile, $i) & @CRLF
        Next
        MemoWrite($new_line)
        _GUICtrlEdit_LineScroll($iMemo, 0, 0xfffffff)
        $cl = $cl_new
    EndIf
    Sleep(500)
Wend

Func _Exit()
    FileClose($hFile)
    GUIDelete($hGUI)
    Exit
EndFunc

It will read the WindowsUpdate.log and display it. If you run wuauclt /detectnow the log file will be updated and displayed in the GUI.

BR,

UEZ

I get

"Auto it Error

Line 4291 (File "CENSORED\test.exe");

Error: Unknown function name."

Edited by foolet

Share this post


Link to post
Share on other sites
UEZ

What are you doing with the script?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
foolet

Never mind I ran just the script and not the build and I get

"Autoit Error

Line 19

MemoWrite($txt)

^ERROR

Error:Unknown function name."

Share this post


Link to post
Share on other sites
UEZ

Ups, forgot that function....:mellow:

See my post with the code!

Sorry,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
foolet

Thanks for your help.

Edited by foolet

Share this post


Link to post
Share on other sites
UEZ

I just added it.

; Write a line to the memo control
Func MemoWrite($sMessage)
;~  GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
    GUICtrlSetData($iMemo, $sMessage, 1)
EndFunc ;==>MemoWrite

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
foolet

Never Mind fixed it :mellow:

Edited by foolet

Share this post


Link to post
Share on other sites
foolet

Is there a way I can make new logs appear at the bottom?

Share this post


Link to post
Share on other sites
UEZ

Check my 3rd post. I updated the script. It should work now that the latest entries will be displayed at the bottom.

BR,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
foolet

Wow, man you are to much of a help! Everything is working well I just have ONE more thing to ask :mellow: Is there a way I can make it so there is no scroll from left to right and if the line fills up it will continue on the line under it?

Share this post


Link to post
Share on other sites
UEZ

I don't know whether you mean this:

remove $WS_HSCROLL from line $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY).

BR,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
foolet

Thanks so much I have a question. How come everytime a run this at least 1 line will stay out of order

:06-29-2010 20:23:05 Base: Got window event: origin=(112, 12) size=(800, 600) title="Window" !undecorated !fixed_size !fullscreen !foreground !minimized open !cursor_hidden icon:window.ico cursor:window.cur absolute 

:06-29-2010 20:19:40 Loader: starting bulk load of block 'StartWindow'

As you can see 20:19:40 is not the latest in the log file. This always happens some line will stray out of order and stay out of order messing up the viewing of the log.

Share this post


Link to post
Share on other sites
UEZ

Indeed, there is something going wrong...

Found the problem -> forgot to erase the variable $new_line.

Code update in post#3

Sorry,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
KaFu

From a performance point of view, wouldn't it be better to wrap the function in a FileGetSize() check?

Global $nFilesize, $nFilesize_new
;....
$nFilesize_new = FileGetSize($File)
if $nFilesize < $nFilesize_new Then
    $nFilesize = $nFilesize_new
    ;....
    $cl_new = _FileCountLines($File)
    If $cl < $cl_new Then
    ;....
endif

Share this post


Link to post
Share on other sites
UEZ

Good idea KaFu!

If you use a more frequent check of the file it is better to check the file size instead using _FileCountLines() which is reading the complete file to enumerate the lines!

Updated my post#3 again!

BR,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
KaFu

Hmmm, thinking about this, wouldn't it even be better not to clear the edit, but use the difference in size ($fs_new - $fs) to performa a FileSetPos() operation instead to move the read pointer to the new content and then do a FileReadLine() loop for new lines only? But I'm not quite sure if FileReadLine() works correctly in conjunction with FileSetPos() :mellow:.

Edit: The FileOpen() handle prevented me to write to the log via notepad... I'm not quite sure if this wouldn't be true for other programs too, thus I think it's better to close the handle once the data has been received. Of course this works only if new data is only appended to the log.

;Coded by UEZ Build 2010-06-30, tweaked by KaFu ;-)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)

Global $iMemo, $new_line
$width = 1024
$height = 600
$hGUI = GUICreate("Realtime Log Reader by UEZ 2010", $width, $height, -1, -1, Default, $WS_EX_TOPMOST)
$iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY)
GUICtrlSetLimit(-1, 0x7FFFFFFF)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then
    $file = $CmdLine[1]
Else
    ;$file = @WindowsDir & "\WindowsUpdate.log"
    $file = @ScriptDir & "\test.log"
EndIf
$hFile = FileOpen($file)
$txt = FileRead($hFile)

GUICtrlSetData($iMemo, $txt, 1)
_GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff)
FileClose($hFile)

$fs = FileGetSize($file)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(1000)
    $fs_new = FileGetSize($file)
    If $fs < $fs_new Then
        $hFile = FileOpen($file,128)
        ConsoleWrite($fs_new - $fs & @crlf)
        FileSetPos($hFile, -($fs_new - $fs), 2)
        $new_line = FileRead($hFile)
        FileClose($hFile)
        GUICtrlSetData($iMemo, $new_line, 1)
        $fs = $fs_new
    EndIf
WEnd

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>_Exit
Edited by KaFu

Share this post


Link to post
Share on other sites
foolet

May I have sex with both of you? Damn you guys are the best.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×