Utility functions

From NetLogger

Jump to: navigation, search

Functions

  • char * NL_get_ipaddr (void)
  • int NL_get_guid (char **buf)
  • int NL_get_someid (char **buf)
  • int NL_sprintf (char *buf, const char *event, int level, char *fmt,...)
  • void split_syslog_url (char *url, char **prog, int *facility)
  • const char * NL_get_level_name (NL_level_t level)
  • NL_level_t NL_get_level_code (const char *name)

Function Documentation

int NL_get_guid (char **buf)   	

Get a GUID. The result is placed in the buffer, NUL-terminated.

This will use uuidlib if the headers uuid/uuid.h were found by configure; otherwise it will try to execute the command 'uuidgen' using popen().

  • Parameters: buf Buffer to put it into, allocated by function. Caller should free this memory when done with it.
  • Returns:Length of data in buffer, not including trailing NUL. -1 is failure
char* NL_get_ipaddr (void)  	

Look up dotted-decimal IP addr of this host.

NL_level_t NL_get_level_code (const char *name)  	

Provide level code for string name.

  • Parameters: name Level name
  • Returns: Level code
const char* NL_get_level_name (NL_level_t level)  	

Provide string name for a level code.

  • Parameters:level Level code
  • Returns: Name of code.
int NL_get_someid (char ** buf)  	

Get some sort of unique-ish identifier, not necessarily conforming to any sort of specification. You can use this if NL_get_guid() fails.

  • Parameters:buf Buffer to put it into, allocated by function. Caller should free this memory when done with it.
  • Returns:Length of data in buffer, not including trailing NUL -1 is failure
int NL_sprintf (char *buf, const char *event, int level, char *fmt,...) 			

The equivalent of sprintf() for NetLogger.

  • Example: see nlsprintf_example.c in examples/ dir
  • Parameters:
    • buf Output buffer, make sure it is at least NL_MAX_FLD * NL_MAX_STR, or know what you are doing.
    • event NL.EVNT field value
    • level NetLogger level, e.g. NL_LVL_INFO
    • fmtFormat string as documented in NL_log_{write,print}
    • ... Variables for format string
  • Returns:Number of bytes written to 'buf'. Like sprintf(). If return val <= 0, there was an error.
void split_syslog_url (char *url, char **prog, int *facility) 			

Split a URL given to NL_open() for syslog into program and facility. See NL_open() for the input URL format.

  • Parameters:
    • url NetLogger syslog output URL
    • prog (OUT) Syslog program name
    • facility (OUT) Syslog facility code