Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing log file 1

Status
Not open for further replies.

NetNodeMan

Technical User
Mar 30, 2005
65
IE
I have a piece of code that writes to a log. It will write a timestamp and a message to that log. I've tried editing the code so that each day a new log is created but all that happens is that every time a message needs to be appended to a log a new file is opened instead.

Could anyone help with this? I have searched the forums but can't find an exact answer to my problem. My code looks as follows:

slog="c:\log\logfilename.txt"
set wshshell=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")

if sError <= 50 then
wscript.echo now() & " Test OK" ' writes to command shell
logfile.writeline now() & " Test OK" ' wries to log
logfile.close
ie.quit
exit do

thanks in advance for any help given. I'm afraid scripting is not a strong point for me
 
sorry i dont understand what your goal is.
do you want to append to a file?
do you want to create a new file?
if you want to do both then what are your criteria for actioning each on?

 
How is logfile instantiated ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok.

Each day I want a new file created so I can looks through daily archives easily. During that day the logfile is appended. On a new day, a new log file is opened and this will then append again until another new day begins i.e. my C: would have:-

test01092005.txt
test02092005.txt
test03092005.txt
test04092005.txt
test05092005.txt

and each of the above files would have maybe 50 entries, each of which is appended during each test. Cheers.
 
You haven't replied to my question.
I don't want to see where logfile is declared, but how it is instantiated (something like SET logfile=)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Apologies:

set logfile=fso.opentextfile(slog,8,true)
 
strLogFile = Day() & Month() & Year() & ".log"
strLogFolder = "d:\logs\"

Set tsLogFile = FSO.CreateTextFile(strLogFolder & strLogFile, 8, True)

tsLogFile.WriteLine "hello it is " & Day()
 
sorry that should have been

FSO.OpenTextFile method instead of CreateTextFile method
 
And where is slog populated ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Not sure what you mean PHV. The only time slog appears in the code is as follows:

dim wshshell, fso, logfile, slog
dim ieErr : ieErr=false 'global scope added 20/07/05


slog="c:\log\test.txt" 'your input
set wshshell=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")

sLoop = "forever"

dState = ""
Do while sLoop = "forever"
sLoop2 = "forever"
Do while sLoop2 = "forever"
set logfile=fso.opentextfile(slog,8,true)

Thanks for your help mrmovie but that doesn't seem to work.
 
what doesnt seem to work?
the opentextfile method with its last param set to true and 8 of the other (append) will do the following.

1. if the file already exists (i.e. middle of day) it will open file and append to it

2. if the file doesnt exist (i.e. when the day changes) it will create the new 'day' file and start appending to that one

etc etc etc
 
I need to declare DAY, MONTH & YEAR somewhere. Apologies movie but I'm a complete novice at this
 
sorry i should stop trying to write psuedo code ;-)

datNow = Now()
strLogFile Day(datNow) & Month(datNow) & Year(datNow)
strLogFolder = "d:\logs\"

Set tsLogFile = FSO.CreateTextFile(strLogFolder & strLogFile, 8, True)

tsLogFile.WriteLine "hello it is " Day(Now())
 
Ok, I've got:
datNow = Now()
strLogFile Day(datNow) & Month(datNow) & Year(datNow)
strLogFolder = "c:\log\"



set wshshell=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")

sLoop = "forever"

dState = ""
Do while sLoop = "forever"
sLoop2 = "forever"
Do while sLoop2 = "forever"
Set logfile = fso.openTextFile(strLogFolder & strLogFile, 8, True)

'************ HTTPS Check

set IE=Wscript.CreateObject("InternetExplorer.Application","objIE_")
IE.Navigate(" IE.visible = True
wait()



But it doesn't seem to work still. Is there anything more I should be doing?
 
when you first run your script you set

strLogFile Day(datNow) & Month(datNow) & Year(datNow)

you then sit in an endless loop, however, in your endless loop you dont re-check what todays date is, therefore it will never advance to the next day.

so, if you include your

datNow = Now()
strLogFile Day(datNow) & Month(datNow) & Year(datNow)

into the loop before the FSO.CreateTextFile then this will sort it out. however, i would not rely on the call to FSO.CreateTextFile to determine if the date has changed, i would suggest this would be slower than keeping the current strLogFile in memory then checking against that i.e.

solution 1.

Do while sLoop = "forever"
sLoop2 = "forever"
Do while sLoop2 = "forever"
datNow = Now()
strLogFile Day(datNow) & Month(datNow) & Year(datNow)
Set logfile = fso.openTextFile(strLogFolder & strLogFile, 8, True)

Solution 2

Do while sLoop = "forever"
sLoop2 = "forever"
Do while sLoop2 = "forever"
datNow = Now()
strTempLogFile Day(datNow) & Month(datNow) & Year(datNow)
If strTempLogFile <> strLogFile Then
strLogFile = strTempLogFile
End If
Set logfile = fso.openTextFile(strLogFolder & strLogFile, 8, True)
 
And to have the log files sorted in chronological order:
strLogFile=Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & ".txt"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top