KBEngine - KBEngine logger

KBEngine API

KBEngine

KBEngine module

This KBEngine module provides Python scripts the ability to control, analyze, and dump certain types of logs.

Member functions

def addTimer( initialOffset, repeatOffset=0, callbackObj=None ):
def delTimer( id ):

Callbacks

def onLoggerAppReady( ):
def onLoggerAppShutDown( ):
def onLogWrote( datas ):
def onReadyForShutDown( ):

Member functions documentation

def addTimer( initialOffset, repeatOffset=0, callbackObj=None ):

Function description:
Registers a timer. The timer triggers the callback function callbackObj. The callback function will be executed the first time after "initialOffset" seconds, and then will be executed once every "repeatOffset" seconds.

Example:
# Here is an example of using addTimer
        import KBEngine
 
        # Add a timer, perform the first time after 5 seconds, and execute once every 1 second. The user parameter is 9
        KBEngine.addTimer( 5, 1, onTimer_Callbackfun )
 
        # Add a timer and execute it after 1 second. The default user parameter is 0.
        KBEngine.addTimer( 1, onTimer_Callbackfun )
 
    def onTimer_Callbackfun( id ):
        print "onTimer_Callbackfun called: id %i" % ( id )
        # If this is a repeated timer, it is no longer needed, call the following function to remove: 
        #     KBEngine.delTimer( id )

parameters:

initialOffset float, specifies the time interval in seconds for the timer to register from the first callback.
repeatOffset float, specifies the time interval (in seconds) between each execution after the first callback execution. You must remove the timer with the function delTimer, otherwise it will continue to repeat. Values less than or equal to 0 will be ignored.
callbackObj function, the specified callback function object

returns:

integer, the internal id of the timer. This id can be used to remove the timer from delTimer.

def delTimer( id ):

Function description:

The delTimer function is used to remove a registered timer. The removed timer is no longer executed. Single-shot timers are automatically removed after the callback is executed, and it is not necessary to use the delTimer function to remove it. If the delTimer function is passed an invalid id (for example, timer was removed), it will generate an error.

A use case is shown in the KBEngine.addTimer example.

parameters:

id integer, which specifies the timer id to remove.


Callback functions documentation

def onLoggerAppReady( ):

Function description:

This function is called back when the current process is ready.
Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

def onLoggerAppShutDown( ):

Function description:

This function is called back when the process shuts down.
Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

def onLogWrote( datas ):

Function description:

If this function is implemented in the script, it is invoked when the logger process obtains a new log.

The database interface is defined in kbengine_defaults.xml->dbmgr->databaseInterfaces.

Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

parameters:

datas bytes, log data.

def onReadyForShutDown( ):

Function description:

If this function is implemented in the script, it is called when the process is ready to exit.

You can use this callback to control when the process exits.

Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

returns:

bool, if it returns True, it allows the process to exit. Returning other values will cause the process to ask again after a period of time.