1984
(Starting to like KiXtart)
2004-11-17 06:13 PM
Tracking/log system

Need some brain storm here, boys n girls!

I’ve done a small program using kixfroms, placed on a network share, and executed by several users directly from the share.

And now:

I need to collect info (logfile) about which users are currently using the program.
A logfile generated containing @Userid and date/time for when that user start the program and when exiting the program. Some kind of time stamp, in and out!

Function TDinout

$date = Join(Split(@date,"/"),"")
$file = $date+'.log'
$path = '\\server\folder\logdir

if $form.visible
$ = Open(1,$path +'\'+$Sfile,5)
$ = WriteLine(1,@USERID+ " Open instance"+@CRLF)
$ = WriteLine(1,@DATE+" "+@TIME+ @CRLF)
$ = Close(1)
endif

if $form.hide
$ = Open(1,$path +'\'+$Sfile,5)
$ = WriteLine(1,@USERID+ " Close instance"+@CRLF)
$ = WriteLine(1,@DATE+" "+@TIME+ @CRLF)
$ = Close(1)
endif

EndFunction

Suggestion please :-)


Bryce
(KiX Supporter)
2004-11-17 06:35 PM
Re: Tracking/log system

a few of the problems that happen with many users accessing a single file using kix.

using open() will lock the file to that current user. you will get errors if another user tried to open() the same file while the file is locked.

Also, you have

$file = $date+'.log'

but you are using the variable $Sfile in the open() code... is this a typo?

About the only way to get aroud the file lock problem is to use a seperate log file for each user.


Code:

Function TDinout
$date = Join(Split(@date,"/"),"")
$file = $date + '.' + @userid + '.log'
$path = '\\server\folder\logdir

if $form.visible
$ = Open(1,$path +'\'+$file,5)
$ = WriteLine(1,@USERID+ " Open instance"+@CRLF)
$ = WriteLine(1,@DATE+" "+@TIME+ @CRLF)
$ = Close(1)
endif

if $form.hide
$ = Open(1,$path +'\'+$file,5)
$ = WriteLine(1,@USERID+ " Close instance"+@CRLF)
$ = WriteLine(1,@DATE+" "+@TIME+ @CRLF)
$ = Close(1)
endif
EndFunction







maciep
(Korg Regular)
2004-11-17 06:45 PM
Re: Tracking/log system

this is a kixform, so you should be able to know when a user starts it and when they are closing it, right?

Code:

;----------------------------------------------
; Start the form
;----------------------------------------------
LogIt("Open")
While $Form.Visible
$=Execute($Form.DoEvents)
Loop
LogIt("Close")
Exit 1
.
.
.
function LogIt($action)
$ = open(1,"Your Log",5)
$ = writeline(1, @date + " " + @time + " " + @userid + ": " + $action + @crlf)
$ = close(1)
endfunction



I don't think that you will have to worry much about the file being locked. how many users will be trying to open or close the form at the same exact time? Plus, is locking even an issue with .txt files? i didn't think it was for some reason.


1984
(Starting to like KiXtart)
2004-11-17 07:33 PM
Re: Tracking/log system

ahh typo, $Sfile should be $file.

Acctually the problem occured when I tried to update the program on network share by remove or overwright it. I found it locked/inuse. "there has been sharing violation"...

I remember on NT4 using winfile with admin rights it was possible to see which users are holding on a specific shared file on fileserver... and then kick them out...

Im not sure how I could check this out from a client on fileserver, W2K , without having full admin rights on server.

It should be possible to see on the folder which i have full permission, who are holding the program...

Hmmm, wonder if there is a tool which we could use to acctually see who are using/holding a file on network share?


1984
(Starting to like KiXtart)
2004-11-17 08:07 PM
Re: Tracking/log system

Using Windows 2000 Resource Kit, command INUSE, I could overwright the program on networkshare by new updated one.
However its not much help, it requires reboot of machine to take effect.
And I will certainly NOT reboot the file server :-)



NTDOCAdministrator
(KiX Master)
2004-11-17 08:14 PM
Re: Tracking/log system

1984

Reviewing many of your posts you do not appear to typically come back and let those that are helping you know if the suggestion worked or not. Not saying you have to thank them, but would be nice to acknowledge that the problem was resolved by their idea/suggestion/code.

Please take the time to come back and end the thread.

Here are just a few of the examples where you have not come back and completed the threads. You have participated, but there appears to be other questions or comments made that you don't always respond to.


http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=127538&page=&view=&sb=5&o=&fpart=2&vc=1
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=126639&page=&view=&sb=5&o=&fpart=2&vc=1
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=112399&page=&view=&sb=5&o=&fpart=2&vc=1


Les
(KiX Master)
2004-11-17 08:15 PM
Re: Tracking/log system

Two things wrong with this line:
$path = '\\server\folder\logdir

First off, it should be share, not folder and second, there is no closing quote.

$path = '\\server\share\logdir'


1984
(Starting to like KiXtart)
2004-11-17 08:44 PM
Re: Tracking/log system

oh, my bad. I am truly sorry about that. I hope nobody thinks that Im ignoring them or so. I am very greatfull for all help and ideas I get from you people, and I truly mean it. Not an excuse but just a explanation is my private situation, which has been very hard these past mounth, and affacting my time and mind.... The life is pain without end.

However I will fulfil the topics and once again thanx a lot all of u kind people who helping a confused mind!

/1984


1984
(Starting to like KiXtart)
2004-11-17 09:18 PM
Re: Tracking/log system

I have now completed some threads.

:-)


1984
(Starting to like KiXtart)
2004-11-17 09:21 PM
Re: Tracking/log system

U r right Les, on both! just as u always r. :-)


Les
(KiX Master)
2004-11-17 09:52 PM
Re: Tracking/log system

I have been worng once or twice.

LonkeroAdministrator
(KiX Master Guru)
2004-11-17 10:03 PM
Re: Tracking/log system

1) once I said I will never be wrong
2) now as I said I was wrong once

ja, that makes 2...


NTDOCAdministrator
(KiX Master)
2004-11-18 07:45 PM
Re: Tracking/log system

There are many posts on using UDF for checking and waiting for open file handles to write a central .INI or LOG file, but my personal preference is to have each user write their own log file to a central share location and then I copy all of them into a single file and import with Excel for reporting.

COPY *.TXT SYSINFO.TXT

There is never any file contention or script waiting. The process can be fully automated by script as well.


Les
(KiX Master)
2004-11-18 07:52 PM
Re: Tracking/log system

One can also write to the event log instead. Never any contention AFAIK. Might want Stevie's custom DLL for that though.

Speaking of the DLL, I seem to have misplaced my copy and can't find a link.


NTDOCAdministrator
(KiX Master)
2004-11-18 08:07 PM
Re: Tracking/log system

Off-Topic, but here you go Les. OR did you mean some other DLL?

KiXtart Messages DLL (Freeware)
http://www.itripoli.com/ikm.asp
iTripoli KiXtart Messages DLL
Install this free KiXtart Messages DLL for clean KiXtart event log entries.

http://www.itripoli.com/downloads/kixtartmessages/kixmsgs_b1.exe


Les
(KiX Master)
2004-11-18 08:12 PM
Re: Tracking/log system

Off-Topic, I think not!
Re: Tracking/log system
Quote:


Install this free KiXtart Messages DLL for clean KiXtart event log entries.





Event log is logging.


NTDOCAdministrator
(KiX Master)
2004-11-18 08:23 PM
Re: Tracking/log system

Okay, I take it back.

Les
(KiX Master)
2004-11-18 08:27 PM
Re: Tracking/log system

Thanks!

Sealeopard
(KiX Master)
2004-11-19 04:03 AM
Re: Tracking/log system

Or write to an Acces Database or SQL database.

JochenAdministrator
(KiX Supporter)
2004-11-19 10:48 AM
Re: Tracking/log system

Has somebody already mentioned WriteProfileString() ???
Hint: INI-files.

Sorry, if I don't understand or even read the entire thread word by word, but that's only because my personal situation at the moment ... In other words I am tired to death atm.

K, back to topic. Logging to textfiles is for obvious reasons not applicable.

SQL/Access database for logging the use of a kixforms script???
That is like shooting on a cat with a cruise missile.

Event logging by a dll ... hmmm ... nice to keep in mind, but administrative overhead for the simple cause.

Conclusion: use a centrally located ini-format file and let the kixforms script write the user with the start time to it, at closing just let the script deleting the section in question.

Am I right or what?

I could even hack a little 'real time' usage statistics form if you ask kindly


NTDOCAdministrator
(KiX Master)
2004-11-19 10:59 AM
Re: Tracking/log system

Come back when you're not so tired Jochen

Reason to log to different log files is to eliminate file locking contention, ie. UDF for open file handles, potential long delays in logging waiting for file to close.

Easier to just let each system log their own log file, then copy all of them into a single file and import into Excel.


JochenAdministrator
(KiX Supporter)
2004-11-19 11:09 AM
Re: Tracking/log system

Sorry Ron,

I don't think so.
The only reason to get a current usage state for 1984, as I read it, is to be sure that noone has it actually running when he wants to update the thing.
So there speaks nothing against using a single ini-file


NTDOCAdministrator
(KiX Master)
2004-11-19 11:30 AM
Re: Tracking/log system

Hmmm... perhaps. I agree not as bad as every user and every logon it doesn't sound like, but he also did not say how many users and how often he thinks the logging would happen. If it were hundreds or thousands of times then I would not opt for single, but if only a few users at random times then yes I agree with you that a single central .INI would be the best method.

JochenAdministrator
(KiX Supporter)
2004-11-19 11:42 AM
Re: Tracking/log system

I'd claim that my suggestion could handle easily a few thousand accesses simultaneously (Which will never happen with anything as we all know)

That's enough ?


Bryce
(KiX Supporter)
2004-11-19 04:12 PM
Re: Tracking/log system

Quote:

I'd claim that my suggestion could handle easily a few thousand accesses simultaneously (Which will never happen with anything as we all know)

That's enough ?




Are you sure? I was running into problems with just 30 users doing a writeprofilestring() once every 30 seconds to the same INI file. I ended going with a separate file for each user because the chances of collisions were too great.

Bryce



Les
(KiX Master)
2004-11-19 07:12 PM
Re: Tracking/log system

Another prob with INI files is that the APIs do not return @Error so if the logging is important, one has to do a read after write verify. Another thing with INI files is that the entire file gets read into memory which may or may not be trivial. Individual INI files as what DOC proposes with flat text files can also be merged into a CSV with an admin script.

INI files are better suited to store changing data while avoiding dups.


1984
(Starting to like KiXtart)
2004-11-20 12:56 PM
Re: Tracking/log system

Or mayby...

Based on maciep code, Jochen point and Docs comment....

Function LogIt($action)

$DTM = Join(Split(@date,"/"),"")
$IPA = Join(Split(@IPADDRESS0,"."),"")

$LIG = $IPA+@userid

$WIP = @IPADDRESS0
$WUS = @USERID

$File = @USERID+".ini"
$LogF = $DTM+'.ini'
$Path = "\\Server\Share\ScriptDir\"
$PNF = $Path+$File

If $action = ("Open")

$ = Open(1,$Path+$File,5)
$ = WriteLine(1,"["+$LIG+"]"+@crlf)
$ = WriteLine(1,"ID="+$WUS+@crlf)
$ = WriteLine(1,"IP="+$WIP+@crlf)
$ = WriteLine(1,"Opened="+@time+@crlf)
$ = WriteLine(1,""+@crlf)
$ = Close(1)

EndIf


If $action = ("Close")

$RIN = ReadProfileString($PNF,"","")

For Each $RINs in Split($RIN,Chr(10))

If $RINs

$RID = ReadProfileString($PNF,$RINs,"ID")
$RIP = ReadProfileString($PNF,$RINs,"IP")
$ROP = ReadProfileString($PNF,$RINs,"Opened")
$RCL = ReadProfileString($PNF,$RINs,"Closed")

If $RIP = $WIP AND $RID = $WUS

$ = Open(1,$Path+$LogF,5)

$ = WriteLine(1,"["+$RID+"]"+@crlf)
$ = WriteLine(1,"IP="+$RIP+@crlf)
$ = WriteLine(1,"Opened="+$ROP+@crlf)
$ = WriteLine(1,"Closed="+@time+@crlf)
$ = WriteLine(1,""+@crlf)

$ = WriteProfileString($PNF,$RINs,$RCL,@time)

$ = Close(1)

EndIf

EndFunction


ChristopheM
(Hey THIS is FUN)
2004-11-20 02:30 PM
Re: Tracking/log system

Just a little remark about the last code.

If you use the file handle "1" in the function, you can have side effect if the calling code is using too the file handle "1".

In the function, you should use something like that :
Code:
$handle = FreeFileHandle()
$ = Open($handle,$Path+$File,5)
$ = WriteLine($handle,"["+$LIG+"]"+@crlf)
$ = WriteLine($handle,"ID="+$WUS+@crlf)
$ = WriteLine($handle,"IP="+$WIP+@crlf)
$ = WriteLine($handle,"Opened="+@time+@crlf)
$ = WriteLine($handle,""+@crlf)
$ = Close($handle)



this is safier.


JochenAdministrator
(KiX Supporter)
2004-11-20 07:35 PM
Re: Tracking/log system

Good point Bryce, but I think this doesn't matter in this case.

I see the form writing only TWICE to the ini file; once it starts it writes the time value to @wksta key (workstationname=@time), and when the form is closed it just deletes the key.
So how often will it happen that only 10 Users open or close the form at the same time ?
See? No problem