Page 1 of 1

Creating logfile

Posted: Thu Jul 01, 2010 11:37 pm
by skiman
Hi,

I want to create a logfile with every menu-option or button that is clicked in my MAIN application.

Anyone who has something for this? I want to add some code to the handler and to save the date, time, caption of clicked option, username, ... in a file. To prevent that this file is getting too big, I would recycle after three months.

If someone has something to share?

Re: Creating logfile

Posted: Fri Jul 02, 2010 9:53 am
by GeneB
At the risk of being branded a heretic, Clayton Jones' "Top Down" demo has a very clever method of keeping track of a user's activity in a program.

Re: Creating logfile

Posted: Sun Jul 04, 2010 4:48 pm
by Auge_Ohr
skiman wrote:I want to create a logfile with every menu-option or button that is clicked in my MAIN application.
Anyone who has something for this? I want to add some code to the handler and to save the date, time, caption of clicked option, username, ... in a file. To prevent that this file is getting too big, I would recycle after three months.
If someone has something to share?
what about :

Code: Select all

PROCEDURE MAIN
   SET ALTER TO myLog.TXT
...
   Userlog("blabla") 
...
   SET ALTER TO
RETURN

PROCEDURE Userlog(cText) 
DEFAULT cText TO ""

   SET CONSOLE OFF    // need for GUI
   SET ALTER ON
   ? ID_USER,DATE(),TIME(), cText
   SET ALTER OFF
   SET CONSOLE ON     // need for GUI
RETURN
you can enhance it with PROCNAME( 1 ), LTRIM( STR( PROCLINE( 1 ) ) ) or NetName() etc. if you like

... shure you can make same with a DBF ;)

Re: Creating logfile

Posted: Sun Jul 04, 2010 11:47 pm
by skiman
Hi Jimmy,

This is not what I'm looking for. I want to add the logsystem to the handler of my main application. This way I can log all the actions a user can click in my application.

Re: Creating logfile

Posted: Mon Jul 05, 2010 3:05 am
by Auge_Ohr
skiman wrote:I want to add the logsystem to the handler of my main application. This way I can log all the actions a user can click in my application.
aha ... so you looking for EventSpy !?
// DESCRIPTION
//
// This file implements an Event Spy that can display all events,
// message parameters and message receivers in an Xbase++ program.
//
// It is great for the Xbase++ novice who wants to see what happens
// in the event loop, and it is a great tool for advanced programmers
// who need to trace single events.
//
// FYI: I have found this tool to be invaluable for "hard core" event
// programming. That is: a single Xbase Part captures all mouse
// messages. In this scenario, it is pretty hard to find a paint event
// that causes wrong display unless you have a complete history of
// events and their receivers.
//
// USAGE
//
// Copy EVENTSPY.DLL and EVENTSPY.LIB to a directory of the LIB path.
// (e.g: \ALASKA\XPPW32\LIB). And link EVENTSPY.LIB to your application

Re: Creating logfile

Posted: Wed Jul 07, 2010 9:01 am
by rdonnay
Chris -

This is what DC_ReadGuiHandler() is for.

Below is some code from \exp19\samples\xdemo\xdemo.prg.

A global handler works in all threads, so it is the first thing called whenever any event occurs.

In the below sample, it is used to invoke the context help system and also to provide print screen routines.

You can add code to log menu or button activations like so:

Code: Select all

IF nEvent == xbeP_Activate
  LogEvent( 'Button Activated', oXbp:caption )
ELSEIF nEvent == xbeP_ItemSelected
  LogEvent( 'Menu Activated', GetCaption(oXbp,mp1,mp2)
If this is what you are looking for and you decide to go with this solution, I will give you the code to get a pointer to the GetList item for the object causing the event.

Code: Select all

// Install global handler.
DC_ReadGuiHandler({|a,b,c,d,e,f|Xdemo_Handler(a,b,c,d,e,f)})

STATIC FUNCTION Xdemo_Handler( nEvent, mp1, mp2, oXbp, oDlg, aGetList )

LOCAL oPrintMenu, GetList[0]

IF nEvent == xbeP_Keyboard .AND. mp1 == xbeK_CTRL_P

  IF Empty(oDlg)
    oDlg := oXbp
    DO WHILE !oDlg:isDerivedFrom('XbpDialog')
      oDlg := oDlg:setParent()
    ENDDO
  ENDIF

  DCSUBMENU oPrintMenu PARENT oXbp

    DCMENUITEM 'Display Image in another Window' ;
      ACTION {||DisplayImage(oDlg)} PARENT oPrintMenu

    DCMENUITEM 'Print WYSIWYG (Current Object)' PARENT oPrintMenu ;
      ACTION {||DC_PrintImage(oDlg,1)} ;
      WHEN {||!oXbp:isDerivedFrom('XbpDialog')}

    DCMENUITEM 'Print WYSIWYG (All TabPages)' PARENT oPrintMenu ;
      ACTION {||DC_PrintImage(oDlg,2)} ;
      WHEN {||oXbp:isDerivedFrom('XbpDialog')}

    DCMENUITEM SEPARATOR PARENT oPrintMenu ;

    DCMENUITEM 'Show Source Code for this Object' ;
      ACTION {||DC_ShowSourceCode(oDlg)} ;
      PARENT oPrintMenu

   DCREAD GUI PARENT AppDeskTop() EXIT

   oPrintMenu:popup( oDlg, {0,0}, 1 , XBPMENU_PU_DEFAULT + XBPMENU_PU_MOUSE_RBDOWN )

   RETURN DCGUI_IGNORE

ENDIF

RETURN DC_HelpHandler( nEvent, mp1, mp2, oXbp, oDlg, GetList )



Re: Creating logfile

Posted: Wed Jul 07, 2010 9:13 am
by skiman
Roger,

Yes, this is what I'm looking for. I didn't knew that there was a possibility to have a global handler which is working in all threats.

Re: Creating logfile

Posted: Fri Jul 09, 2010 12:42 pm
by rdonnay
I modified one of my sample programs to also write out Menu and Button activations to a log file.

Unzip the following file to your \exp19\samples\menu directory.

Pbuild MSGBOX.XPJ

Run MSGBOX.EXE and select the File -> Open Test Window.

A file name EVENTS.LOG will be created and any button pushed or menu item selected will be logged.

http://donnay-software.com:8080/support ... agebox.zip

Re: Creating logfile

Posted: Sat Jul 10, 2010 1:49 am
by skiman
Hi Roger,

Thanks for the sample. I will add it to my application.