Windows Message Logger

image


Code Samples for  Paul Bunyan Windows Message Logger:


C API Sybase
C++ API InstallShield
Visual Basic Batch Files / Shell Scripts
SQL Server  



C API Sample
Paul Bunyan message logging is made available to C code through the use of statically linked libraries.

#include <PB.h>

VOID main(INT argc, CHAR* argv[])

{
PB_COMPONENT cp = {L"My component", L"", TRUE, 0};
PB_CONTEXT cx = {L"My context", TRUE, 0};

/* Set default ‘component’ and 'context'.*/
PBSetDefaultComponent(&cp, PB_MODULE_DEFAULT);
PBSetDefaultContext(&cx, PB_THREAD_DEFAULT);

/*
* Log a message using the default component and context set above.
* Note that PBLog() uses printf() formatting.
*/
PBLog(NULL, NULL, PB_WARNING, "This program (%s) does nothing.", argv[0]);

/* Log same message passing component and context explicitly. */
PBLog(&cp, &cx, PB_WARNING, "This program (%s) does nothing.", argv[0]);
}

Back to top




C++ API Sample
Paul Bunyan message logging is made available to C++ code through the use of statically linked libraries.

#include <PB.h>

VOID main(INT argc, CHAR* argv[])

{
CPBComponent    cp("My component");        // Set default 'component'.
CPBContext      cx("Some context");        // Set default 'context'.
CPBLogger       lgr;                       // Logger object
CPBScopeLogger  slgr(PB_STATUS, "main()"); // Log entrance/exit of scope 'main()'.

// Log a message using the default component and context set above.
// Note that Paul Bunyan uses printf() formatting.
lgr.Log(PB_WARNING, "This program (%s) does nothing.", argv[0]);

// Log same message using non-object API
PBLog(PB_WARNING, "This program (%s) does nothing.", argv[0]);
}

Back to top




Visual Basic
Paul Bunyan message logging is made available to Visual Basic through a COM API as well as through a Win32 interface currently available on the API Extensions page.  Below are two samples illustrating simple logging from Visual Basic using Paul Bunyan's COM API.  Note: the COM object PB.Logger.1 must be referenced within the Visual Basic IDE in order for the variable type PBLogger to be recognized.

Private Sub Sample1()

Dim lgr As New PBLogger

lgr.Log "WARNING", "Some warning..."
End Sub

Private Sub Sample2()
Dim lgr As New PBLogger
Dim slgr As New PBScopeLogger
Dim i As Integer

'Secure messages generated by this lgr object with a message key
lgr.MessageKey = "My Password"

lgr.Component = "The RAS Wrapper"
lgr.Module = "RAS.vdp"

'Verbose and Info messages will be prefiltered out by this object.
lgr.Exclude = "vi"

'Will not be logged because of prefiltering flags set above.
lgr.Log "v", "A verbose message..."

'Will not be logged because of prefiltering flags set above.
lgr.Log "INFO", "An info message..."

'Logs a status message.
lgr.Log "STS", "A status message..."

'Logs a message used for regression testing.
lgr.Log "r", "A regression test message..."

For i = 1 To 1000
'Logs the value of the variable i but will be prefiltered out unless the prefiltering flags above are changed.

lgr.Log "V", "i = " & Str(i)
Next i
End Sub

Back to top




SQL Server
Paul Bunyan message logging is made available to SQL Server stored procedures through the implementation of a SQL Server Extended Stored Procedure interface. The syntax for PBLog() may be obtained at any time by typing 'PBLog' in the Query Analyzer window.

Syntax:

exec PBLog [@msgtype, @msg, [@component], [@context], [@line]]
Example:
CREATE PROCEDURE PBLogTest AS
    exec PBLog 'V', 'Test message for PBLog().', 'PBLogTest', '', 1
    exec PBLog 'E', 'An error message.'

Back to top




Sybase
Paul Bunyan message logging is made available to Sybase stored procedures through the implementation of a Win32 interface.

Syntax:

call PBLog [@msgtype, @msg, [@component], [@context], [@line]]
Example:
create procedure MyStoredProcedure(in strCP char(20),
                                   in strCX char(20),
                                   in strArg1 char(10),
                                   in strArg2 char(10))

// First PBLog() call uses default/null values for CP/CX/Line
// Second PBLog() call specifies CP/CX/Line

begin

    //... code

    call PBLog('v', 'In MyStoredProcedure()');

    if (strArg1 = strArg2) then
        call PBLog('e', 'Args are same:' + strArg1 + strArg2, strCP, strCX, 15);
    end if

    //... code

end

Back to top




InstallShield
Paul Bunyan message logging is made available to InstallShield scripts through the implementation of a Win32 interface. While InstallShield scripts may also use Paul Bunyan via the COM interface API it is sometimes more appropriate to use a single-line API.

Syntax:

prototype INT PBFWAPI.PBLog(BYVAL STRING,   //msg type
                            BYVAL STRING,   //msg
                            BYVAL STRING,   //component
                            BYVAL STRING,   //context
                            LONG);          //line number

Example:

#include "ifx.h"                   //DO NOT REMOVE
#include "PBFWInstallShield.rul"   //Paul Bunyan logging API
#include "..\_ISUser\Resource.h"   //Custom user dll


function OnFirstUIBefore()
begin
    PBLog(PB_INFO, "Informational message text...", "My CP", "My CX", __LINE__);
    return 0;
end;

Back to top




Command Line API / Batch Files / Shell Scripts
Paul Bunyan message logging is made available to command line processors, batch (.bat) files, and shell scripts through the use of the command line API component, PBLog.exe.

    PBLog.exe   Beginning test sequence.
    . . .
    PBLog.exe   Test sequence completed.

Back to top


Contact us | View site map


image


image
image
©Copyright 1997-2010 Diamond Sierra Software All Rights Reserved
For more information feel free to Contact Us

Apollo Beach Internet Web Design and Hosting
©Site Design 2009-2010