r1 - 2013-09-17 - 22:48:12 - ShubhamSinghalYou are here: NTP >  Dev Web > GoogleSummerOfCode > GSoC2013LoggingDebugging > GSoC2013LoggingDebuggingFunctionsAndTypes
NTP users are strongly urged to take immediate action to ensure that their NTP daemons are not susceptible to being used in distributed denial-of-service (DDoS) attacks. Please also take this opportunity to defeat denial-of-service attacks by implementing Ingress and Egress filtering through BCP38.

ntp-4.2.8p13 was released on 07 March 2019. It addresses 1 medium-severity security issue in ntpd, and provides 17 non-security bugfixes and 1 other improvements over 4.2.8p12.

Please see the NTP Security Notice for vulnerability and mitigation details.

Are you using Autokey in production? If so, please contact Harlan - he's got some questions for you.

NTP Logging and Debugging Functions and Types

Types Used In API

  • logc_loggerType_t: Enum type stores value STDOUT, STDERR, FILEOUT, RBUFOUT, SYSLOG
  • logc_logLevel_t: Enum type stores value for log level like LOG_INFO, LOG_ERR etc.
  • logc_errRecordType_t: Enum type stores the format to show logs like ERR, ERR_TAG, ERR_TAG_TIMESTAMP.

Functions Used To Trigger API

RegisterLogger:

Each Logger is registered before being used. It is registered using following format

logc_registerLogger(uint16_t ident, logc_loggerType_t type, logc_logLevel_t level)

Parameters:

  • ident (I) identifier for the logger.
  • type (I) Type of publisher. Could be STDOUT, STDERROUT or FILEOUT, SYSLOG.
  • level (I) Log level see section Log Level for detailed information.

ChangeLogLevel:

Each logger has its own log level which is set by registering a logger or can be changed with a function call.

logc_changeLogLevel(uint16_t ident,logc_logLevel_t level)

Parameters:

  • ident (I) identifier of the logger.
  • level (I) new log level.

SetLogFile:

To use a file for logging output it must be first defined with this function call.

logc_setLogFile(uint16_t ident,const char* const filename)

Parameters:

  • ident (I) identifier of the logger.
  • filename (I) name of the file. The file is opened with the append option.

SetRingBuffer:

Ringbuffer logging can be very useful if you do not want to continously log each message to terminal or a file but want to have the information of the current behaviour at a particular time (error occured ..). The ringbuffer is created with a given size and overwrites the last messages if overflows, so only the last log messages, depending on the size of the buffer, are included. The ringbuffer is a kind of a singleton and can be used by several loggers. It must be created once with the call:

logc_setRingbuffer(uint16_t ident, const size_t size)

Parameters:

  • ident (I) identifier of the logger.
  • size (I) size of the ringbuffer.

ReadRingBufferContent

Reads the content of the global rinbuffer.

logc_readRingbuffer(uint16_t ident, char* const buffer, const size_t size, size_t* const wBytes)

Parameters:

  • ident (I) identier of the logger.
  • buffer (O) buffer to write content.
  • size (I) size of content buffer.
  • wBytes (O) number of bytes written in buffer

LogFormat

A logger has two different types of log formats, one for error logging and one for info logging. Info logging in this context means the logc_log... and the logc_logArray... functions.The default values of the log format is ERR for error messages and CLEAN for info messages.

For Error Logging:

logc_setLogFormat(uint16_t ident, logc_errRecordType_t errForm, logc_logRecordType_t logFrom)

Parameters:

  • ident (I) identifier of the logger.
  • errForm (I) format for error logging.
  • logForm (I) format for info logging.

Example:

ERR

  • [ERROR] : error message

ERR_TAG

  • [ERROR] 0xYYYYYYYY : error message

ERR_TAG_TIMESTAMP

  • [ERROR] 0xYYYYYYYY day mon dd hh:mm:ss YYYY : error message

ERR_TIMESTAMP_TAG

  • [ERROR] day mon dd hh:mm:ss YYYY : error message

TIMESTAMP_ERR_TAG

  • day mon dd hh:mm:ss YYYY [ERROR] 0xYYYYYYYY : error message

Here TAG 0xYYYY is used to store tags like "refclock.oncore.Model187"

For INFO Logging:

logc_logRecordType_t is used for info logging and is defined as an enumeration with the entries:

Example:

CLEAN

  • message

TIMESTAMP

  • day mon dd hh:mm:ss YYYY : message

Log Functions

Four base types of log functions are provided by log_debug, error logging, info logging, array logging and trace logging. Except trace logging, which is just a enter- and leave-function message, each type has a call with a log level as parameter and one call per log level. All functions with log levels in their names could be controlled (besides the log levels) with define switches. So it is intended to use these functions to be able to use this powerful feature and define at pre-processor time which objects should be linked and have an influence of the source code size.

1) Error Logging

Prints error messages to a logger with a given log level.

logc_logError( uint16_t ident, logc_logLevel_t level, logc_error_t err, const char* formatStr, ... )

Parameters:

  • ident (I) identifier of the logger.
  • level (I) log level of this log statement.
  • err (I) error to log.
  • formatStr (I) log message.

2) Info Logging

Prints log messages to a logger with a given log level.

logc_log( uint32_t ident, logc_logLevel_t level, const char* formatStr, ... )

Parameters:

  • ident (I) identifier of the logger.
  • level (I) log level of this log statement.
  • formatStr (I) log message.

3) Array Logging

Prints data array described by a descriptor to a given logger and log level.

logc_logArray( uint16_t ident, logc_logLevel_t level, const char* desc, const uint8_t* array, size_t len )

Parameters:

  • ident (I) identifier of the logger.
  • level (I) log level of this log statement.
  • desc (I) description of the data array.
  • array (I) data array.
  • len (I) size of data array.

4) Trace Logging

Prints entering of a function. Must be enabled with the define LOGC_ENABLE_LOW_LEVEL.

logc_logEnter( uint16_t ident, const char* function )

Parameters:

  • ident (I) identifier of the logger.
  • function (I) function name which is entered.

Prints leaving of a function. Must be enabled with the dene LOGC_ENABLE_LOW_LEVEL.

logc_logLeave( uint16_t ident, const char* function )

Parameters:

  • ident (I) identifier of the logger.
  • function (I) function name which is leaved.

Define Switch

log_debug provides define switch to control the behaviour of logging at pre-processor time.

Enables the FILE, LINE and FUNCTION macros for each log function.

  • LOGC_HAVE_FLF

-- ShubhamSinghal - 2013-09-17

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
SSL security by CAcert
Get the CAcert Root Certificate
This site is powered by the TWiki collaboration platform
IPv6 Ready
Copyright & 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding the site? Send feedback