NetBurner 3.5.6
PDF Version
Syslog

Functions

int SysLog (const char *format,...)
 Send a formatted log message to the syslog server.
 
int SysLogVia (int interfaceNum, const char *format,...)
 Send a formatted log message via a specific network interface.
 

Variables

IPADDR SysLogAddress
 Destination IP address for syslog messages.
 

Detailed Description

#include< syslog.h>


Function Documentation

◆ SysLog()

int SysLog ( const char * format,
... )

#include <syslog.h>

Send a formatted log message to the syslog server.

This function sends a formatted text message to the configured syslog destination using UDP. The message format follows printf() conventions with full support for format specifiers including floating-point numbers.

The function:

  • Formats the message according to the format string and arguments
  • Prepends a syslog header (priority and timestamp information)
  • Sends the message via UDP to SysLogAddress on port 514
  • Uses the default network interface for transmission
  • Returns immediately without waiting for acknowledgment (UDP is connectionless)
Parameters
formatPrintf-style format string supporting all standard format specifiers:
  • d, i - signed decimal integer
  • u - unsigned decimal integer
  • x, X - hexadecimal
  • f, e, g - floating-point (increases code size)
  • s - string
  • c - character
  • p - pointer
  • Plus width, precision, and length modifiers
...Variable arguments corresponding to format specifiers in the format string
Returns
  • Number of characters sent (positive value) on success
  • Negative value on error (e.g., network unavailable, invalid parameters)
  • 0 if SysLogAddress is not configured (0.0.0.0)
Note
This function includes floating-point formatting support which adds approximately 30-40KB to the application binary size. If code size is critical, consider alternatives for logging.
Messages are sent immediately without buffering. High-frequency logging can impact network performance.
Maximum message length is typically limited by the UDP packet size (approximately 1400 bytes for safe transmission).
Warning
Do not call this function from interrupt context or with interrupts disabled, as it performs network I/O operations.
Basic Usage Examples:
#include <syslog.h>
void BasicLogging() {
// Simple text message
SysLog("Application started");
// Formatted with integers
int temperature = 72;
SysLog("Temperature: %d degrees", temperature);
// Multiple values
int sensor1 = 100, sensor2 = 200;
SysLog("Sensors: S1=%d, S2=%d", sensor1, sensor2);
// Floating-point values
float voltage = 3.3f;
SysLog("Supply voltage: %.2f V", voltage);
// Hexadecimal output
uint32_t address = 0x08000000;
SysLog("Flash base address: 0x%08X", address);
}
Advanced Usage Examples:
// Error logging with context
void LogError(const char *function, int errorCode) {
SysLog("ERROR in %s: code=%d", function, errorCode);
}
// Network event logging
void OnNetworkEvent(const char *event, IPADDR addr) {
SysLog("Network: %s from %hI", event, addr);
}
// Performance monitoring
void LogPerformance(const char *operation, uint32_t ticks) {
float milliseconds = (float)ticks / TICKS_PER_SECOND * 1000.0f;
SysLog("PERF: %s took %.2f ms", operation, milliseconds);
}
// Structured logging with severity
#define LOG_ERROR(msg, ...) SysLog("ERROR: " msg, ##__VA_ARGS__)
#define LOG_WARN(msg, ...) SysLog("WARN: " msg, ##__VA_ARGS__)
#define LOG_INFO(msg, ...) SysLog("INFO: " msg, ##__VA_ARGS__)
void StructuredLogging() {
LOG_ERROR("Connection failed to 192.168.1.100");
LOG_WARN("Buffer usage at 90%%");
LOG_INFO("Processing request #%d", requestCount);
}
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
Conditional Logging:
// Enable/disable logging at compile time
#ifdef DEBUG_LOGGING
#define DEBUG_LOG(msg, ...) SysLog("DEBUG: " msg, ##__VA_ARGS__)
#else
#define DEBUG_LOG(msg, ...) do {} while(0)
#endif
void ConditionalLogging() {
DEBUG_LOG("Entering function");
// ... function code ...
DEBUG_LOG("Exiting function");
}
See also
SysLogVia()
SysLogAddress

◆ SysLogVia()

int SysLogVia ( int interfaceNum,
const char * format,
... )

#include <syslog.h>

Send a formatted log message via a specific network interface.

This function is identical to SysLog() but allows explicit selection of the network interface to use for transmission. This is primarily useful when:

  • Logging from network driver code
  • Multiple network interfaces are active
  • Routing or interface-specific debugging is needed
  • Sending logs on a specific VLAN or network segment

The function operates identically to SysLog() but routes the UDP packet through the specified interface rather than using the default routing table.

Parameters
interfaceNumZero-based index of the network interface to use for transmission:
  • 0: First network interface (usually primary Ethernet)
  • 1: Second network interface (if available)
  • etc. Invalid interface numbers will cause the message to be dropped.
formatPrintf-style format string (same as SysLog())
...Variable arguments corresponding to format specifiers
Returns
  • Number of characters sent (positive value) on success
  • Negative value on error (e.g., invalid interface, network unavailable)
  • 0 if SysLogAddress is not configured (0.0.0.0)
Note
This function is typically only needed for specialized network driver development or multi-interface debugging scenarios.
The specified interface must be active and have a valid IP configuration for the message to be sent successfully.
Warning
Ensure the interfaceNum is valid for your hardware platform. Invalid interface numbers will fail silently or return an error code.
Usage Examples:
#include <syslog.h>
#include <netinterface.h>
// Log via specific interface
void LogViaInterface() {
// Log via primary interface (eth0)
SysLogVia(0, "Message from primary interface");
// Log via secondary interface (eth1), if available
if (GetNumberOfInterfaces() > 1) {
SysLogVia(1, "Message from secondary interface");
}
}
// Network driver debugging
void DriverLog(int ifNum, const char *event) {
SysLogVia(ifNum, "IF%d: %s", ifNum, event);
}
// Multi-interface monitoring
void MonitorAllInterfaces() {
int numInterfaces = GetNumberOfInterfaces();
for (int i = 0; i < numInterfaces; i++) {
if (pifb) {
SysLogVia(i, "Interface %d: IP=%hI, Link=%s",
i, pifb->ip_addr,
pifb->IsLinkActive() ? "UP" : "DOWN");
}
}
}
// VLAN-specific logging
void LogToVLAN(int vlanInterface, const char *message) {
SysLogVia(vlanInterface, "VLAN: %s", message);
}
Network interface configuration block class for interface control and configuration.
Definition netinterface.h:245
InterfaceBlock * GetInterfaceBlock(int interface=0)
Get an InterfaceBlock control and configuration object.
int SysLogVia(int interfaceNum, const char *format,...)
Send a formatted log message via a specific network interface.
Network Driver Usage:
// Typical use in network driver code
void NetworkDriverRx(int ifNum, PoolPtr pp, uint16_t size) {
// Log received packet on specific interface
SysLogVia(ifNum, "RX on IF%d: %d bytes", ifNum, size);
// Process packet...
}
void NetworkDriverTx(int ifNum, uint16_t size) {
// Log transmitted packet
SysLogVia(ifNum, "TX on IF%d: %d bytes", ifNum, size);
}
Main buffer structure for network and serial communication.
Definition buffers.h:90
See also
SysLog()
SysLogAddress
GetNumberOfInterfaces()
GetInterfaceBlock()

Variable Documentation

◆ SysLogAddress

IPADDR SysLogAddress
extern

#include <syslog.h>

Destination IP address for syslog messages.

This global variable specifies the IP address of the host or server where syslog messages should be sent. The syslog protocol uses UDP port 514 by default (this is hardcoded and cannot be changed).

Default behavior:

  • If set to IPADDR(0,0,0,0) or not initialized: Messages are sent to the UDP broadcast address 255.255.255.255
  • If set to a specific IP address: Messages are sent directly to that host
Note
The destination address can be changed at any time during runtime to redirect logging to different hosts or servers.
Broadcast messages (255.255.255.255) may not cross router boundaries. For logging across subnets, specify an explicit unicast address.
Usage Examples:
#include <syslog.h>
#include <ipaddr.h>
void SetupSyslog() {
// Send to specific syslog server
SysLogAddress = IPADDR(192, 168, 1, 100);
SysLog("Syslog initialized, sending to 192.168.1.100");
// Send to broadcast (all hosts on local network)
SysLogAddress = IPADDR(255, 255, 255, 255);
SysLog("Broadcasting syslog messages");
// Disable syslog by setting to zero
SysLogAddress = IPADDR(0, 0, 0, 0);
}
// Dynamic syslog server selection
void SelectSyslogServer(const char *serverIP) {
IPADDR addr;
if (AsciiToIp(serverIP, &addr)) {
SysLogAddress = addr;
SysLog("Syslog server changed to %s", serverIP);
} else {
iprintf("Invalid IP address: %s\r\n", serverIP);
}
}
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6)
Definition nettypes.h:568
IPADDR SysLogAddress
Destination IP address for syslog messages.
See also
SysLog()
SysLogVia()