# ctaSetTraceLevel

Sets the trace mask for a service on the specified context.

#### Prototype

DWORD ctaSetTraceLevel ( CTAHD ctahd, char *svcname, unsigned tracemask)

Argument | Description
ctahd | Context handle. ctahd cannot be NULL.
svcname | Pointer to the name of the service for which you will change the tracemask. Use CTA to modify the Natural Access trace mask.
tracemask | Trace mask of the service. See the Details section for valid values.

#### Return values

Return value | Description
SUCCESS |
CTAERR_INVALID_CTAHD |
CTAERR_NOT_FOUND | Service is not open on the context.
CTAERR_NOT_INITIALIZED | Natural Access is not initialized. Call ctaInitialize first.
CTAERR_SVR_COMM | Server communication error.

#### Details

ctaSetTraceLevel sets the trace mask for a service on a specified context. If svcname is NULL, the function sets the trace masks of all services opened within the ctahd to the new tracemask.

Use the following macros from ctadef.h for the tracemask argument:

Value | Description
--- | ---
CTA_TRACEMASK_DRIVER_COMMANDS | Trace commands to devices.
CTA_TRACEMASK_DRIVER_EVENTS | Trace events to devices.
CTA_TRACEMASK_DISP_COMMANDS | Trace service-to-service commands.
CTA_TRACEMASK_DISP_EVENTS | Trace service-to-service events.
CTA_TRACEMASK_API_COMMANDS | Trace application commands.
CTA_TRACEMASK_API_EVENTS | Trace application events.
CTA_TRACEMASK_API_ERRORS | Trace application errors.
CTA_TRACEMASK_SVC_ERRORS | Trace internal service errors.
CTA_TRACEMASK_DEBUG_BIT0 | Trace service-specific messages.
CTA_TRACEMASK_DEBUG_BIT1 | Trace service-specific messages.
CTA_TRACEMASK_DEBUG_BIT2 | Trace service-specific messages.
CTA_TRACEMASK_DEBUG_BIT3 | Trace service-specific messages.

Use the following macros to unify related groups of tracemask values:

Value | Description
--- | ---
CTA_TRACEMASK_ALL_COMMANDS | Trace all commands.
CTA_TRACEMASK_ALL_EVENTS | Trace all events.
CTA_TRACEMASK_ALL | Trace everything.

ctdaemon must be running and you must have set the global tracemask in ctdaemon for tracing to work. This setting affects all processes (and all contexts within the process) that have enabled tracing with ctaInitialize. For more information, refer to Natural Access Server: ctdaemon.

Based on the flags set in tracemask, the specified service logs internal trace information to ctdaemon. Each service that manages a device can respond to the CTA_TRACEMASK_DRIVER_COMMANDS or CTA_TRACEMASK_DRIVER_EVENTS bits in tracemask.

CTA_TRACEMASK_DISP_COMMANDS, CTA_TRACEMASK_API_COMMANDS, CTA_TRACEMASK_API_EVENTS, and CTA_TRACEMASK_API_ERRORS are used to enable Natural Access dispatcher tracing. Use CTA as the service name to enable this capability.

The debug bits are service specific. Refer to the documentation for the service for more information.

Refer to Error tracing for more information.

#### See also

ctaLogTrace

#### Example

/*
* These functions will enable/disable tracing dispatcher and API events on the
* given context. To trace driver commands each service must be specified
* separately. To set the global trace mask, use the ctdaemon. This enables
* tracing on all contexts in processes that have enabled tracing.
*/
void DemoTraceEventsOn(CTAHD ctahd)
{
ctaSetTraceLevel( ctahd, "CTA", CTA_TRACEMASK_ALL_EVENTS );
}
void DemoTraceEventsOff(CTAHD ctahd)
{
ctaSetTraceLevel( ctahd, "CTA", 0 );
}