Qp0zLprintf()--Print Formatted Job Log Data


  Syntax
 #include <qp0ztrc.h>

 int Qp0zLprintf(char *format-string, ...);

  Service Program Name: QP0ZCPA

  Default Public Authority: *USE

  Threadsafe: Yes

The Qp0zLprintf() function prints user data specified by format-string as an information message type to the job log.

If a second parameter, argument-list, is provided, Qp0zLprintf() converts each entry in the argument-list and writes the entry to the job log according to the corresponding format specification in format-string. If there are more entries in argument-list than format specifications in format-string, the extra argument-list entries are evaluated and then ignored. If there are less entries in argument-list than format specifications in format-string, the job log output for those entries is undefined, and the Qp0zLprintf() function may return an error.

The data printed by Qp0zLprintf() is buffered one line at a time, and a new message in the job log is forced every 512 characters if a new line (\n) is not detected in the data before that time. The buffer used by Qp0zLprintf() is not physically written when the application ends. To ensure messages are written to the job log, always use a new line (\n) at the end of each format-string.

An application should not use the tracing function in performance critical code. These functions are intended for debugging exceptions or error conditions.


Parameters

format-string
(Input) The format string representing the format of the data to be printed. See the printf() function in ILE C/C++ Run-Time Library FunctionsLink to PDFfor a description of valid format strings.

... (argument-list)
(Input) An optional list of arguments that contain entries to be formatted and printed to the job log.

Authorities

None.


Return Value

value Qp0zLprintf() was successful. The value returned is the number of characters successfully printed.
-1 Qp0zLprintf() was not successful. The errno variable is set to indicate the error.


Error Conditions

If Qp0zLprintf() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than that listed here.

[EINVAL]

The value specified for the argument is not correct.

A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.

An argument value is not valid, out of range, or NULL. An invalid format-string or argument-list was specified.

[EFAULT]

The address used for an argument is not correct.

In attempting to use an argument in a call, the system detected an address that is not valid.

While attempting to access a parameter passed to this function, the system detected an address that is not valid.


Usage Notes

None.


Related Information


Example

The following example uses Qp0zLprintf() to produce output in the job log.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <qp0ztrc.h>

#define  THREADDATAMAX    128

void *theThread(void *parm)
{
   char                    *myData = parm;

   Qp0zLprintf("%.8x %.8x: Entered the %s thread\n",
               pthread_getthreadid_np(), myData);
   free(myData);
   return NULL;
}

int main(int argc, char **argv)
{
   pthread_t             thread, thread2;
   int                   rc=0;
   char                 *threadData;


   printf("Create two threads\n");
   Qp0zUprintf("Tracing creation of two threads\n");

   threadData = (char *)malloc(THREADDATAMAX);
   sprintf(threadData, "50%% Cotton, 50%% Polyester");
   rc = pthread_create(&thread, NULL, theThread, threadData);
   if (rc) {
     printf("Failed to create a %s thread\n", threadData);
     exit(EXIT_FAILURE);
   }

   threadData = (char *)malloc(THREADDATAMAX);
   sprintf(threadData, "Lacquered Camel Hair");
   rc = pthread_create(&thread2, NULL, theThread, threadData);
   if (rc) {
     printf("Failed to create a %s thread\n", threadData);
     exit(EXIT_FAILURE);
   }

   printf("Wait for threads to complete\n");
   rc = pthread_join(thread, NULL);
   if (rc) { printf("Failed pthread_join() 1\n"); exit(EXIT_FAILURE); }

   rc = pthread_join(thread2, NULL);
   if (rc) { printf("Failed pthread_join() 2\n"); exit(EXIT_FAILURE); }
   return 0;
}


Job Log Output:

The following two job log messages where generated by the example shown above. The output was retrieved from the spooled file created when the job ran to completion and when the job log was retained. The informational messages contain the contents of the Qp0zLprintf() function calls.


br>
*NONE    Information    01/05/98   16:55:05   QP0ZCPA      QSYS    *STMT   QP0ZCPA    QSYS     *STMT
                         From module . . . . . . . . :   QP0ZUDBG
                         From procedure  . . . . . . :   Qp0zVLprintf
                         Statement . . . . . . . . . :   296
                         To module . . . . . . . . . :   QP0ZUDBG
                         To procedure  . . . . . . . :   Qp0zVLprintf
                         Statement . . . . . . . . . :   296
                         Thread  . . . . : 0000001A
                         Message . . . . : 00000000 0000001a: Entered the 50% Cotton, 50% Polyester thread
*NONE   Information   01/05/98   16:55:05   QP0ZCPA     QSYS    *STMT   QP0ZCPA    QSYS     *STMT
                         From module . . . . . . . . :   QP0ZUDBG
                         From procedure  . . . . . . :   Qp0zVLprintf
                         Statement . . . . . . . . . :   296
                         To module . . . . . . . . . :   QP0ZUDBG
                         To procedure  . . . . . . . :   Qp0zVLprintf
                         Statement . . . . . . . . . :   296
                         Thread  . . . . : 0000001B
                         Message . . . . : 00000000 0000001b: Entered the Lacquered Camel Hair thread



API introduced: V4R3

[ Back to top | Problem Management APIs | APIs by category ]