High Performance OPC UA Server SDK  1.4.1.263
Trace Module

Writing trace messages. More...

Macros

#define TRACE_LEVEL_DEBUG   1
 Identifier for debug trace level: also logs internal variables/states, only useful for developers.
 
#define TRACE_LEVEL_DATA   2
 Identifier for data trace level: logs process data (e.g. More...
 
#define TRACE_LEVEL_INFO   4
 Identifier for info trace level: informational (e.g. More...
 
#define TRACE_LEVEL_FUNC_ENTER   8
 Identifier for function enter trace level.
 
#define TRACE_LEVEL_FUNC_LEAVE   16
 Identifier for function leave trace level.
 
#define TRACE_LEVEL_FUNC   24
 Identifier for function trace level.
 
#define TRACE_LEVEL_NOTICE   32
 Identifier for notice trace level: normal but significant condition, e.g. More...
 
#define TRACE_LEVEL_WARNING   64
 Identifier for warning trace level. More...
 
#define TRACE_LEVEL_ERROR   128
 Identifier for error trace level: error conditions, e.g. More...
 
#define TRACE_LEVEL_INSANE   256
 Identifier for insane trace level, produces a lot of output! This is used for cyclic events. More...
 
#define TRACE_LEVEL_ALL   511
 Combination of all trace levels.
 
#define TRACE_FAC_PLATFORM   1
 Identifier for platform facility.
 
#define TRACE_FAC_NETWORK   2
 Identifier for network facility.
 
#define TRACE_FAC_CRYPTO   4
 Identifier for crypto facility.
 
#define TRACE_FAC_IPC   8
 Identifier for IPC facility.
 
#define TRACE_FAC_BASE   16
 Identifier for base facility.
 
#define TRACE_FAC_MEMORY   32
 Identifier for memory facility.
 
#define TRACE_FAC_UATCP   64
 Identifier for UATCP facility.
 
#define TRACE_FAC_ENCODER   128
 Identifier for encoder facility.
 
#define TRACE_FAC_SESSION   256
 Identifier for session facility.
 
#define TRACE_FAC_PROVIDER   512
 Identifier for provider facility.
 
#define TRACE_FAC_APPLICATION   1024
 Identifier for application facility.
 
#define TRACE_FAC_ADDRSPACE   2048
 Identifier for address space facility.
 
#define TRACE_FAC_TIMER   4096
 Identifier for timer facility.
 
#define TRACE_FAC_PKI   8192
 Identifier for timer facility.
 
#define TRACE_FAC_SUBSCRIPTION   16384
 Identifier for subscription facility.
 
#define TRACE_FAC_CLIENT   32768
 Identifier for client facility.
 
#define TRACE_FAC_USERAPPLICATION   65536
 Reserved for the user application. More...
 
#define TRACE_FAC_FILEFORMAT   (1 << 17)
 Identifier for file format facility.
 
#define TRACE_FAC_PUBSUB   (1 << 18)
 Identifier for pubsub facility.
 
#define TRACE_FAC_ALL   ((1 << 19) - 1)
 Combination of all facilities.
 
#define TRACE_SECMASK_SHOW_USERNAME   1
 
#define TRACE_SECMASK_SHOW_PASSWORD   2
 
#define TRACE_SECMASK_SHOW_IPADDRESS   4
 
#define TRACE_SECMASK_SHOW_ALL   7
 Enables all sensitive information. More...
 
#define TRACE_DEBUG(facility, format, ...)   trace_log(TRACE_LEVEL_DEBUG, facility, format, ##__VA_ARGS__)
 Convenience define for tracing with debug level.
 
#define TRACE_DATA(facility, format, ...)   trace_log(TRACE_LEVEL_DATA, facility, format, ##__VA_ARGS__)
 Convenience define for tracing with data level.
 
#define TRACE_INFO(facility, format, ...)   trace_log(TRACE_LEVEL_INFO, facility, format, ##__VA_ARGS__)
 Convenience define for tracing with info level.
 
#define TRACE_NOTICE(facility, format, ...)   trace_log(TRACE_LEVEL_NOTICE, facility, format, ##__VA_ARGS__)
 Convenience define for tracing with notic level.
 
#define TRACE_WARNING(facility, format, ...)   trace_log(TRACE_LEVEL_WARNING, facility, format, ##__VA_ARGS__)
 Convenience define for tracing with warning level.
 
#define TRACE_ERROR(facility, format, ...)   trace_log(TRACE_LEVEL_ERROR, facility, format, ##__VA_ARGS__)
 Convenience define for tracing with error level.
 
#define TRACE_INSANE(facility, format, ...)
 Convenience define for tracing with insane level.
 
#define TRACE_ENTER(facility, funcname)   trace_log(TRACE_LEVEL_FUNC_ENTER, facility, "> %s\n", funcname); trace_indent()
 Trace with function enter level, adds an indent.
 
#define TRACE_RETURN(facility, funcname)   trace_unindent(); trace_log(TRACE_LEVEL_FUNC_LEAVE, facility, "< %s\n", funcname)
 Trace with function leave level, removes an indent.
 
#define TRACE_RETURNERR(facility, funcname, result)   trace_unindent(); trace_log(TRACE_LEVEL_FUNC_LEAVE, facility, "< %s - return 0x%08X\n", funcname, result)
 Trace with function leave level, removes an indent and prints errorcode.
 
#define TRACE_ENTERD(facility, funcname)   trace_log(TRACE_LEVEL_INSANE, facility, "> %s\n", funcname); trace_indent()
 Trace function enter with insane level, adds an indent.
 
#define TRACE_RETURND(facility, funcname)   trace_unindent(); trace_log(TRACE_LEVEL_INSANE, facility, "< %s\n", funcname)
 Trace function leave with insane level, removes an indent.
 
#define TRACE_RETURNERRD(facility, funcname, result)   trace_unindent(); trace_log(TRACE_LEVEL_INSANE, facility, "< %s - return 0x%08X\n", funcname, result)
 Trace function leave with insane level, removes an indent and prints errorcode.
 
#define TRACE_HEXDUMP(facility, data, len)   trace_hexdump(TRACE_LEVEL_DATA, facility, data, len)
 
#define TRACE_USERNAME(x)   trace_username(x)
 
#define TRACE_PASSWORD(x)   trace_password(x)
 
#define TRACE_IPv4(x)   trace_ipv4(x)
 
#define TRACE_IPv6(x)   trace_ipv6(x)
 

Functions

int trace_openlog (int level_mask, int facility_mask)
 Initialize the trace backend. More...
 
void trace_log (int level, int facility, const char *format,...) TRACE_FORMAT_ARGUMENT(3
 Write to trace. More...
 
void void trace_hexdump (int level, int facility, const unsigned char *data, size_t count)
 Writes the hexdump of the given data to trace output. More...
 
void trace_closelog (void)
 Close the trace backend.
 
int trace_change_trace_level (int level_mask, int facility_mask)
 Change the trace level and facility. More...
 
int trace_change_security_level (int security_mask)
 Changes the security level of the trace output. More...
 
int trace_get_security_level (void)
 
int trace_enabled (int level)
 Test if a certain trace level is enabled. More...
 
void trace_indent (void)
 Add an indent to all further traces messages.
 
void trace_unindent (void)
 Remove an indent from all further trace messages.
 
const char * trace_username (const char *username)
 Returns the username as-is if TRACE_SECMASK_SHOW_USERNAME is set, otherwise the string "<hidden>". More...
 
const char * trace_password (const char *password)
 Returns the password as-is if TRACE_SECMASK_SHOW_PASSWORD is set, otherwise the string "XXX". More...
 
const char * trace_ipv4 (const unsigned char ipv4[4])
 Returns the string representation of the given IPv4 address if TRACE_SECMASK_SHOW_IPADDRESS is set, otherwise an anonymised version of it. More...
 
const char * trace_ipv6 (const unsigned char ipv6[16])
 Returns the string representation of the given IPv6 address if TRACE_SECMASK_SHOW_IPADDRESS is set, otherwise an anonymised version of it. More...
 

Detailed Description

Writing trace messages.

The SDK has multiple trace backends implemented, which can be selected using the cmake switch TRACE_BACKEND. Each of them writes the trace to a different location. To disable the trace completely the cmake switch TRACE_ENABLED must be disabled.

Each trace message is written with a level to indicate the severity of the message and a facility to assign the message to a component. Depending of the trace backend the trace messages may be prefixed with timestamps, the output can be colored, etc. See Trace Module for more general information about the different trace backends.

Macro Definition Documentation

◆ TRACE_FAC_USERAPPLICATION

#define TRACE_FAC_USERAPPLICATION   65536

Reserved for the user application.

Not used in the SDK.

◆ TRACE_LEVEL_DATA

#define TRACE_LEVEL_DATA   2

Identifier for data trace level: logs process data (e.g.

read/written values)

◆ TRACE_LEVEL_ERROR

#define TRACE_LEVEL_ERROR   128

Identifier for error trace level: error conditions, e.g.

file access denied, out of memory, etc.

◆ TRACE_LEVEL_INFO

#define TRACE_LEVEL_INFO   4

Identifier for info trace level: informational (e.g.

app started, shutdown, connect, disconnect, subscription created, ...)

◆ TRACE_LEVEL_INSANE

#define TRACE_LEVEL_INSANE   256

Identifier for insane trace level, produces a lot of output! This is used for cyclic events.

◆ TRACE_LEVEL_NOTICE

#define TRACE_LEVEL_NOTICE   32

Identifier for notice trace level: normal but significant condition, e.g.

authentication denied

◆ TRACE_LEVEL_WARNING

#define TRACE_LEVEL_WARNING   64

Identifier for warning trace level.

e.g. the certificate may expire soon, only 1MB of memory left, etc.

◆ TRACE_SECMASK_SHOW_ALL

#define TRACE_SECMASK_SHOW_ALL   7

Enables all sensitive information.

Function Documentation

◆ trace_change_security_level()

int trace_change_security_level ( int  security_mask)

Changes the security level of the trace output.

By default no sensitive information like username, passwords or IP addresses are written to the trace. The prevents accidental leakage of sensitive information if trace are sent to other people, e.g. to get support.

However you can enable tracing of sensitive information by calling this function and set the security_mask. Note that this only has the desired effect if all trace lines use the special trace macros which honer this security mask.

See also
TRACE_USERNAME
TRACE_PASSWORD
TRACE_IPv4
TRACE_IPv6
Parameters
security_maskBitwise ORed TRACE_SECMASK_* values.
Returns
Zero on success, UA_EBADINVALIDARGUMENT if the mask is invalid.

◆ trace_change_trace_level()

int trace_change_trace_level ( int  level_mask,
int  facility_mask 
)

Change the trace level and facility.

Parameters
level_maskNew trace level mask.
facility_maskNew trace facility mask.
Returns
Zero on success or errorcode on failure

◆ trace_enabled()

int trace_enabled ( int  level)

Test if a certain trace level is enabled.

Parameters
levelTrace level to test.
Returns
Zero if the specified trace level is disabled

Test if a certain trace level is enabled.

If the trace level is disabled this function returns zero.

◆ trace_hexdump()

void void trace_hexdump ( int  level,
int  facility,
const unsigned char *  data,
size_t  count 
)

Writes the hexdump of the given data to trace output.

Parameters
levelLevel to trace to.
facilityFacility to trace to.
dataPointer to data which should be dumped.
countLength of data in bytes.

◆ trace_ipv4()

const char* trace_ipv4 ( const unsigned char  ipv4[4])

Returns the string representation of the given IPv4 address if TRACE_SECMASK_SHOW_IPADDRESS is set, otherwise an anonymised version of it.

You should used the macro TRACE_IPv6 instead of calling this function directly.

Example usage:

char ipv4[4];
TRACE_DEBUG(TRACE_FAC_APPLICATION, "New connection from IP %s.\n", TRACE_IPv4(ipv4));

◆ trace_ipv6()

const char* trace_ipv6 ( const unsigned char  ipv6[16])

Returns the string representation of the given IPv6 address if TRACE_SECMASK_SHOW_IPADDRESS is set, otherwise an anonymised version of it.

You should used the macro TRACE_IPv6 instead of calling this function directly.

Example usage:

char ipv6[16];
TRACE_DEBUG(TRACE_FAC_APPLICATION, "New connection from IP %s.\n", TRACE_IPv6(ipv6));

◆ trace_log()

void trace_log ( int  level,
int  facility,
const char *  format,
  ... 
)

Write to trace.

Parameters
levelLevel to trace to.
facilityFacility to trace to.
formatFormat specifier like for printf().

◆ trace_openlog()

int trace_openlog ( int  level_mask,
int  facility_mask 
)

Initialize the trace backend.

Parameters
level_maskBitwise OR of trace levels to trace.
facility_maskBitwise OR of trace facilities to trace.
Returns
Zero on success or errorcode on failure

◆ trace_password()

const char* trace_password ( const char *  password)

Returns the password as-is if TRACE_SECMASK_SHOW_PASSWORD is set, otherwise the string "XXX".

You should used the macro TRACE_PASSWORD instead of calling this function directly.

Example usage:

void user_logon(const char *username, const char *password)
{
TRACE_DEBUG(TRACE_FAC_APPLICATION, "The user '%s' identified itself with password '%s'.\n", TRACE_USERNAME(username), TRACE_PASSWORD(password));
}

◆ trace_username()

const char* trace_username ( const char *  username)

Returns the username as-is if TRACE_SECMASK_SHOW_USERNAME is set, otherwise the string "<hidden>".

You should used the macro TRACE_USERNAME instead of calling this function directly.

Example usage:

void user_logon(const char *username, const char *password)
{
TRACE_DEBUG(TRACE_FAC_APPLICATION, "The user '%s' identified itself with password '%s'.\n", TRACE_USERNAME(username), TRACE_PASSWORD(password));
}