Creating logfile

This forum is for eXpress++ general support.
Post Reply
Message
Author
skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Creating logfile

#1 Post 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?
Best regards,

Chris.
www.aboservice.be

User avatar
GeneB
Posts: 158
Joined: Sun Jan 31, 2010 8:32 am
Location: Albuquerque, New Mexico, USA
Contact:

Re: Creating logfile

#2 Post 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.

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Creating logfile

#3 Post 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 ;)
greetings by OHR
Jimmy

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Creating logfile

#4 Post 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.
Best regards,

Chris.
www.aboservice.be

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Creating logfile

#5 Post 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
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Creating logfile

#6 Post 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 )


The eXpress train is coming - and it has more cars.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Creating logfile

#7 Post 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.
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Creating logfile

#8 Post 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
The eXpress train is coming - and it has more cars.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Creating logfile

#9 Post by skiman »

Hi Roger,

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

Chris.
www.aboservice.be

Post Reply