Jump to content
Sign in to follow this  
Alpinestar

Reading Log file

Recommended Posts

Alpinestar

Hello

Its probably something really simple but I keep getting mixed results on the code below. As it stands now, I'm getting no results. The purpose of the code is firstly find the newest log file (thanks to PsaltyDS), then read it for key words/phrases and log them in another log file. This was working fine until I extended it with 2 more additional elseif statements. My brain is hurting !!!!

CODE
#include <file.au3>

#include <Constants.au3>

Dim $array

$FindSolusLog = _FileGetNewest("C:\Documents and Settings", 0, 1, "solus.log")

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Info - Found latest Solus.log file in: " & $FindSolusLog[0])

If @error Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Info - No Previous Solus.log found")

_OutPut()

EndIf

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Info - SRD is reading from: " & $FindSolusLog[0])

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Waiting for Solus.log to update")

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Analysing Solus.log")

_FileWriteLog(@ScriptDir & "\4SBackup.log", "*******************" & @CRLF)

ConsoleWrite("Info - Analysing Solus.log" & @CRLF)

While 1

$line = FileReadLine($FindSolusLog[0])

If @error = -1 Then ExitLoop

If StringInStr($line, "Unknown Proxy Server Info") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises Unknown Proxy Server Setting")

_Error()

ElseIf StringInStr($line, "An error has occurred while establishing a connection to the server") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Sims.net issue")

_Error()

ElseIf StringInStr($line, "Unable to contact the CES network") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus can not connect to the CES network")

_Error()

ElseIf StringInStr($line, "no new downloads available") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises that there are no downloads available")

_Error()

ElseIf StringInStr($line, "DownloadFailed") And StringInStr($line, "Succeeded") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to download Upgrade files")

_Error()

ElseIf StringInStr($line, "Database upgrades not completed correctly") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Database has not been upgraded")

_Error()

ElseIf StringInStr($line, "InstallFailed") And StringInStr($line, "Succeeded") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Files failed to Upgrade")

_Error()

ElseIf StringInStr($line, "InstallSucceeded") And StringInStr($line, "Failed") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Files failed to Upgrade")

_Success()

ElseIf StringInStr($line, "DownloadSucceeded") And StringInStr($line, "Succeeded") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded")

_Success()

ElseIf StringInStr($line, "Applied Database Upgrade") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Database has been upgraded")

_Success()

ElseIf StringInStr($line, "InstallSucceeded") And StringInStr($line, "Succeeded") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Install files completed successfully!")

_Success()

ElseIf StringInStr($line, "Removed package") Then

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Gizmo - (Solus.log) Database and Files Upgraded Successfully - Notifying Schools Manager")

_Completed()

Else

_FileWriteLog(@ScriptDir & "\4SBackup.log", "Nothing to Report - (Solus.log) Going to Output")

_Nothing()

EndIf

WEnd

FileClose($FindSolusLog[0])

Share this post


Link to post
Share on other sites
Jos

This is not much we can test with but have you done some debugging to ensure its reading the correct file and what it is reading?

Something like:

#include <file.au3>
#include <Constants.au3>
Dim $array
$FindSolusLog = _FileGetNewest("C:\Documents and Settings", 0, 1, "solus.log")
_FileWriteLog(@ScriptDir & "\4SBackup.log", "Info - Found latest Solus.log file in: " & $FindSolusLog[0])
If @error Then
    _FileWriteLog(@ScriptDir & "\4SBackup.log", "Info - No Previous Solus.log found")
    _OutPut()
EndIf
_FileWriteLog(@ScriptDir & "\4SBackup.log", "Info - SRD is reading from: " & $FindSolusLog[0])
_FileWriteLog(@ScriptDir & "\4SBackup.log", "Waiting for Solus.log to update")
_FileWriteLog(@ScriptDir & "\4SBackup.log", "Analysing Solus.log")
_FileWriteLog(@ScriptDir & "\4SBackup.log", "*******************" & @CRLF)
ConsoleWrite("Info - Analysing Solus.log" & @CRLF)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FindSolusLog[0] = ' & $FindSolusLog[0] & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
While 1
    $line = FileReadLine($FindSolusLog[0])
    If @error = -1 Then ExitLoop
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $line = ' & $line & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
    If StringInStr($line, "Unknown Proxy Server Info") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises Unknown Proxy Server Setting")
        _Error()
    ElseIf StringInStr($line, "An error has occurred while establishing a connection to the server") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Sims.net issue")
        _Error()
    ElseIf StringInStr($line, "Unable to contact the CES network") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus can not connect to the CES network")
        _Error()
    ElseIf StringInStr($line, "no new downloads available") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises that there are no downloads available")
        _Error()
    ElseIf StringInStr($line, "DownloadFailed") And StringInStr($line, "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to download Upgrade files")
        _Error()
    ElseIf StringInStr($line, "Database upgrades not completed correctly") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Database has not been upgraded")
        _Error()
    ElseIf StringInStr($line, "InstallFailed") And StringInStr($line, "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Files failed to Upgrade")
        _Error()
    ElseIf StringInStr($line, "InstallSucceeded") And StringInStr($line, "Failed") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Files failed to Upgrade")
        _Success()
    ElseIf StringInStr($line, "DownloadSucceeded") And StringInStr($line, "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded")
        _Success()
    ElseIf StringInStr($line, "Applied Database Upgrade") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Database has been upgraded")
        _Success()
    ElseIf StringInStr($line, "InstallSucceeded") And StringInStr($line, "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Install files completed successfully!")
        _Success()
    ElseIf StringInStr($line, "Removed package") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Gizmo - (Solus.log) Database and Files Upgraded Successfully - Notifying Schools Manager")
        _Completed()
    Else
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Nothing to Report - (Solus.log) Going to Output")
        _Nothing()
    EndIf
WEnd
FileClose($FindSolusLog[0])

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Alpinestar

Hi Jos

Thanks for the quick reply. After running your debug script, I noticed that the log was actually not be read. This is due to the fact I had not opened it in read only mode before hand. Anyway my results log is coming up duplicates now, is there anything I can do for it not to duplicate. I have attached an example log file that I'm reading from.

Edit: I had to get rid of the Else statement from my script.

2009-03-07 12:30:58 : Info - Found latest Solus.log file in: d:\Data\email\solus.log

2009-03-07 12:30:58 : Info - SRD is reading from: d:\Data\email\solus.log

2009-03-07 12:30:58 : Waiting for Solus.log to update

2009-03-07 12:30:58 : Analysing Solus.log

2009-03-07 12:30:58 : *******************

2009-03-07 12:30:58 : Success - (Solus.log) Upgrade files have been downloaded

2009-03-07 12:30:58 : Success - (Solus.log) Upgrade files have been downloaded

2009-03-07 12:30:58 : Success - (Solus.log) Database has been upgraded

2009-03-07 12:30:58 : Success - (Solus.log) Install files completed successfully!

2009-03-07 12:30:58 : Success - (Solus.log) Install files completed successfully!

2009-03-07 12:30:58 : Gizmo - (Solus.log) Database and Files Upgraded Successfully - Notifying Schools Manager

solus.txt

Edited by Alpinestar

Share this post


Link to post
Share on other sites
Jos

it is pretty logical that those lines show up twice:

The second part of this test is always true when the first part is true as "Succeeded" is also part of "DownloadSucceeded".

ElseIf StringInStr($line, "DownloadSucceeded") And StringInStr($line, "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded")
        _Success()

try these test updates:

ElseIf StringInStr($line, "DownloadSucceeded" & @TAB & "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded")
        _Success()


    ElseIf StringInStr($line, "InstallSucceeded" & @TAB & "Succeeded") Then
        _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Install files completed successfully!")
        _Success()
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Alpinestar

Jos

Will give it a go. Thanks for all your help

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  

×