Jump to content

FileWriting


 Share

Recommended Posts

I've got some script like that:

$log = FileOpen("edi.log", 1)
[...]
_logwrite(0, "***************")
[...]
_logwrite(1, "Unable to connect")
[...]
FileClose($log)

Func _logwrite($typ,$text) ; Writes to the log
    Select
        Case $typ = 0
            If $LVL > 2 Then FileWriteLine($log, _NowCalc() & ": " & $text)
        Case $typ = 1
            If $LVL > 1 Then FileWriteLine($log, _NowCalc() & ": WARNING: " & $text)    
        Case $typ = 2
            If $LVL > 0 Then FileWriteLine($log, _NowCalc() & ": ERROR: " & $text)
    EndSelect
EndFunc ;==> _logwrite()

A normal run of my program should look like that:

2007/11/05 22:41:03:*******************************************

2007/11/05 22:41:03: Starting job for VWR

2007/11/05 22:41:04: No ORS to upload

2007/11/05 22:41:04: No INV to upload

2007/11/05 22:41:04: No orders to download

2007/11/05 22:41:04: Job ended

Now the problem is, when I run the program more than once, it gives me always twice the text (in one run), like:

2007/11/05 22:12:07:*******************************************

2007/11/05 22:12:07: Starting job for Fisher

2007/11/05 22:12:08: No ORS to upload

2007/11/05 22:12:08: No INV to upload

2007/11/05 22:12:08: No orders to download

2007/11/05 22:12:08: Job ended

2007/11/05 22:12:08:*******************************************

2007/11/05 22:12:08: Starting job for Fisher

2007/11/05 22:12:08: No ORS to upload

2007/11/05 22:12:08: No INV to upload

2007/11/05 22:12:09: No orders to download

2007/11/05 22:12:09: Job ended

I watched my prog with the Process-Monitor from sysinternals (http://www.sysinternals.com) and it shows me only 1 writing access to the logfile, so the whole text is written in one session.

Why do I always get the double text? I just don't get it...

Because when i open the log once with an editor an resave it, then it works once again (the text is normal), but all further runs, the text is doubled again

!!Important!! It could also be a bug, because the problem came about in the same time as i updated AutoIt the last time

I would be grateful for any help / hints

Edited by tannerli
Link to comment
Share on other sites

I've got some script like that:

$log = FileOpen("edi.log", 1)
[...]
_logwrite(0, "***************")
[...]
_logwrite(1, "Unable to connect")
[...]
FileClose($log)

Func _logwrite($typ,$text) ; Writes to the log
    Select
        Case $typ = 0
            If $LVL > 2 Then FileWriteLine($log, _NowCalc() & ": " & $text)
        Case $typ = 1
            If $LVL > 1 Then FileWriteLine($log, _NowCalc() & ": WARNING: " & $text)    
        Case $typ = 2
            If $LVL > 0 Then FileWriteLine($log, _NowCalc() & ": ERROR: " & $text)
    EndSelect
EndFunc ;==> _logwrite()

A normal run of my program should look like that:

2007/11/05 22:41:03:*******************************************

2007/11/05 22:41:03: Starting job for VWR

2007/11/05 22:41:04: No ORS to upload

2007/11/05 22:41:04: No INV to upload

2007/11/05 22:41:04: No orders to download

2007/11/05 22:41:04: Job ended

Now the problem is, when I run the program more than once, it gives me always twice the text (in one run), like:

2007/11/05 22:12:07:*******************************************

2007/11/05 22:12:07: Starting job for Fisher

2007/11/05 22:12:08: No ORS to upload

2007/11/05 22:12:08: No INV to upload

2007/11/05 22:12:08: No orders to download

2007/11/05 22:12:08: Job ended

2007/11/05 22:12:08:*******************************************

2007/11/05 22:12:08: Starting job for Fisher

2007/11/05 22:12:08: No ORS to upload

2007/11/05 22:12:08: No INV to upload

2007/11/05 22:12:09: No orders to download

2007/11/05 22:12:09: Job ended

I watched my prog with the Process-Monitor from sysinternals (http://www.sysinternals.com) and it shows me only 1 writing access to the logfile, so the whole text is written in one session.

Why do I always get the double text? I just don't get it...

Because when i open the log once with an editor an resave it, then it works once again (the text is normal), but all further runs, the text is doubled again

!!Important!! It could also be a bug, because the problem came about in the same time as i updated AutoIt the last time

I would be grateful for any help / hints

Look at the time stamps - they are not the same. That is not doubled up entries. You somehow made all those calls to the _logwrite() function.

BTW - AutoIt already has a pretty sweet log function in the File.au3 UDF: _FileWriteLog(). When you use that, you don't have to mess with open/close or generating the timestamp.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The Problem is, this Prog runs now every ten minutes. I just picked out a place in the log, and most of the times, the timestamps ARE the same. I just built in a _Singleton check, maybe it is called twice by the taskscheduler.

But thanks for the hint with _FileWriteLog, I never saw that one in the help file before.

EDIT:

I changed my _logwrite() function to

Func _logwrite($typ,$text) ; Schreibt eine Zeile ins Log
    Select
        Case $typ = 0
            _FileWriteLog($log, $text)
        Case $typ = 1
            _FileWriteLog($log, "WARNING: " & $text)    
        Case $typ = 2
            _FileWriteLog($log, "ERROR: " & $text)
    EndSelect
EndFunc ;==> _logwrite()

And this works well, thx

Edited by tannerli
Link to comment
Share on other sites

  • 3 weeks later...

Just for info:

I worked the problem out.... I am so terribly dumb sometimes.

I configured the Taskscheduler on my server using RDP, and then (for those who know RDP) the scheduler did run once under my RDP Session and once under the main console session. So my prog did start twice at the same time... and so I ended up with these confusing log entries....

Link to comment
Share on other sites

Just for info:

I worked the problem out.... I am so terribly dumb sometimes.

I configured the Taskscheduler on my server using RDP, and then (for those who know RDP) the scheduler did run once under my RDP Session and once under the main console session. So my prog did start twice at the same time... and so I ended up with these confusing log entries....

Glad you figured it out. And thanks for posting the solution.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...