Sign in to follow this  
Followers 0
MonsieurOUXX

[SOLVED] why won't this simple Logger work?

7 posts in this topic

#1 ·  Posted (edited)

this is my code :

============= FILE : logging.au3 ===========
 
#Include <Date.au3>
 
 
func LogMsg($msg)
    $fileName = "log.txt"
    $file = FileOpen($fileName, 1)
    if $file = -1 Then
        MsgBox(0, "Error", "could not open file " & $fileName)
        Exit
    EndIf
    
    FileWriteLine($file, _Date_Time_GetSystemTime() & " : " & $msg)
    FileFlush ($file)
    FileClose($file)        
    
endFunc
 
============= FILE: mytest.au3 =============
 
#include "logging.au3"
 
LogMsg("this is a test")

As you can see it's very basic and very straightforward.

Yet, after I execute "mytest.au3" in SciTE, the file "log.txt" exists but remains desperately empty...

I'm on Windows 7 with a Symantec antivirus

Edited by MonsieurOUXX

Share this post


Link to post
Share on other sites



Basic support question that should have been in General Help and Support (It's now moved there). I don't think you understand what _Date_Time_GetSystemTime() actually returns.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <GuiConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>

 LogMsg("this is a test")

func LogMsg($msg)
    $fileName = "log.txt"
    $file = FileOpen($fileName, 1)
    if $file = -1 Then
        MsgBox(0, "Error", "could not open file " & $fileName)
        Exit
    EndIf
    $tDate = _Date_Time_GetSystemTime()
    FileWriteLine($file, _Date_Time_SystemTimeToDateStr($tDate) & " : " & $msg)
    FileFlush ($file)
    FileClose($file)

endFunc

Edited by sleepydvdr

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Sorry about posting to the wrong forum! I'm pretty much new around here ( I was around some time ago but since then I lost all my good habits :graduated: ). My apologies again.

And both of you are absolutely right: I added "_Date_Time_GetSystemTime()" in a rush at the very end and trusted the name without checking the specs. I was so focused on the file management that I forgot to double-check that, thinking "oh, whatever it outputs I'll have time later to correct it and format it better". Shame on me!

Thank you so much, guys/ladies.

EDIT: Actually it doesn't change anything, the problem remains....

Edited by MonsieurOUXX

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

BUMP.

Even with that change, the file remains empty...

EDIT :

OH WAIT that's actually hilarious (well, from my perspective it is).

The issue was simply that since my early tests there were hundreds of blank lines at the beginning of the file.

All I had to do was... to scroll down. :graduated:

And if you think I'm retarded, well have a look at Windows 7's theme, where everything is pale gray and where nothing catches the eye (ninja scrollbars...)

Edited by MonsieurOUXX

Share this post


Link to post
Share on other sites

BUMP.

Even with that change, the file remains empty...

The code I gave you works for me. But there is an easier way:

#Include <File.au3>
_FileWriteLog("Log.txt", "This is a test.")

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

See my update above

All my apologies, really.

Edited by MonsieurOUXX

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  
Followers 0