# debug

The debug class is automatically created and can be globally accessed by using the reference * debug. It has to be freed after the iomux Run function in the main class.
In your app code, you shouldn't use the debug class in release builds directly,
but instead the log functions of your AppInstance class.
If you use VisualGDB or Valgrind to run your App, the logs are written to STDOUT.
Otherwise they are written to a logfile under /var/log/apps/appname-timestamp.txt.
There are up to 5 log files for each App and each log file can have a maximum size of 5 MB.

## Logs within an AppInstance object

The AppInstance object itself provides log functions, where the appName and appDomain are always printed
to make out different AppInstance objects.
In addition, these log functions do only write logs to the log file, if the corresponding log flag
for the application is set within the taskmanager or your code.
See appservice.htm for more information.

## LOG_FLAGS and IInstanceLog base class

See appservice.htm for more information.

## The following functions can be used to debug data independent of the current log flags.

printf

  Provides formatted output logging similar to standard C library printf. Writes formatted text to the application's log output using a format specifier and variable arguments.

  #### Parameters

  const char * format | Format string specifying output structure
  ... | Variable arguments matching format specifiers

hexdump

  Outputs a hexadecimal and ASCII representation of binary data. Useful for debugging raw buffers and network packets.

  #### Parameters

  const void * buffer | Binary data to display
  size_t size | Length of data in bytes

appPrintf

  Extended printf variant that prefixes output with application context. Formats messages with appName@appDomain identification for debugging multi-instance scenarios.

  #### Parameters

  const char * appName | Application instance identifier
  const char * appDomain | Execution context domain
  const char * format | Format string
  ... | Variable arguments

appPrintfV

  va_list variant of appPrintf for use in wrapper functions. Accepts pre-packaged variable arguments list.

  #### Parameters

  const char * appName | Application instance identifier
  const char * appDomain | Execution context domain
  const char * format | Format string
  va_list ap | Pre-initialized arguments list

appHexdump

  Contextual hexdump with application identification. Combines appPrintf identification with hexdump functionality.

  #### Parameters

  const char * appName | Application instance identifier
  const char * appDomain | Execution context domain
  const void * buffer | Binary data to display
  size_t size | Length of data in bytes

SetLogging

  Controls global logging output. Disabling prevents log messages from being recorded.

  #### Parameters

  bool on | True enables logging, false disables

SetHexdump

  Toggles hexdump output globally. Useful for reducing log volume during control flow analysis.

  #### Parameters

  bool on | True enables hexdumps, false disables

SetLogFileSize

  Configures maximum log file size. Typically managed by the App Platform Manager.

  #### Parameters

  off_t size | Maximum file size in bytes

SaveLogs

  By calling this function, a new log file with fileNameSuffix in it's name is created and the content of the current log file is copied to this file for later inspection. This file can be downloaded inside the App Platform Manager with "Download All" on the specific App service.

  #### Parameters

  const char * fileNameSuffix | Create a log file with this suffix.

Example:

      debug->printf("MyClass::TestFunction %s %x", "Hallo", 1234);
      // 2016-11-07 13:29:05.663103 MyClass::TestFunction Hallo 0x42d
      byte buf[4];
      debug->HexDump(buf, sizeof(buf));
      // 2016-11-07 13:29:05.663103 Hexdump of address 0x7EFFFC60, 4 bytes:
      // 2016-11-07 13:29:05.663301 0x00000000   00 00 00 00