libniftylog  0.1.3-[v0.1.3-5-g810592a]
lightweight logging/debugging library
Modules | Macros | Typedefs | Enumerations | Functions
Logging API

Logging functionality. More...

Collaboration diagram for Logging API:

Modules

 NftLogMechanism
 API to provide different logging mechanisms.
 
 Version handling
 version handling
 

Macros

#define MAX_MSG_SIZE   4096
 
#define NFT_LOG_ENV_LEVEL   "NFT_LOG_LEVEL"
 
#define NFT_LOG_ENV_MECHANISM   "NFT_LOG_MECHANISM"
 
#define NFT_LOG(level, msg, ...)   nft_log($level, __FILE__, __func__, __LINE__, $msg, ##__VA_ARGS__)
 
#define NFT_LOG_PERROR(msg)   nft_log(L_ERROR, __FILE__, __func__, __LINE__, "%s: %s", $msg, strerror(errno))
 
#define NFT_LOG_NULL(ret)   { nft_log(L_NOISY, __FILE__, __func__, __LINE__, "NULL pointer received."); return ret; }
 
#define NFT_TODO()   NFT_LOG(L_ERROR, "Not implemented, yet. Please tell developers that you need this.")
 

Typedefs

typedef void( NftLogFunc) (void *userdata, NftLoglevel level, const char *file, const char *func, int line, const char *msg)
 

Enumerations

enum  NftLoglevel {
  L_INVALID = -1, L_MAX, L_VERY_NOISY, L_NOISY,
  L_DEBUG, L_VERBOSE, L_INFO, L_NOTICE,
  L_WARNING, L_ERROR, L_QUIET, L_MIN
}
 

Functions

void nft_log (NftLoglevel level, const char *file, const char *func, int line, const char *msg,...)
 
void nft_log_va (NftLoglevel level, const char *file, const char *func, int line, const char *msg, va_list args)
 
void nft_log_func_register (NftLogFunc *func, void *userdata)
 
NftResult nft_log_level_set (NftLoglevel loglevel)
 
NftLoglevel nft_log_level_get ()
 
const char * nft_log_level_to_string (NftLoglevel loglevel)
 
NftLoglevel nft_log_level_from_string (const char *name)
 
bool nft_log_level_is_noisier_than (NftLoglevel a, NftLoglevel b)
 
void nft_log_print_loglevels ()
 

Detailed Description

Logging functionality.

Messages are logged using the default mechanism (stderr). A custom NftLogFunc can be registered using nft_log_func_register() to enable the application to process logging messages additionally (e.g. to log to a GUI)

Other convenience macros include:

Macro Definition Documentation

#define MAX_MSG_SIZE   4096

maximum length of log-message in bytes

Referenced by nft_log_va().

#define NFT_LOG_ENV_LEVEL   "NFT_LOG_LEVEL"

name of environment variable to hold loglevel

Referenced by nft_log_level_get(), and nft_log_level_set().

#define NFT_LOG_ENV_MECHANISM   "NFT_LOG_MECHANISM"

name of environment variable to hold mechanism

Referenced by nft_log_mechanism_set().

#define NFT_LOG (   level,
  msg,
  ... 
)    nft_log($level, __FILE__, __func__, __LINE__, $msg, ##__VA_ARGS__)

convenience macro for nft_log()

Note
No \n is needed at end of string.
Example: NFT_LOG(LL_INFO, "Reading config file \"s"...", config);

Referenced by nft_log_check_version(), nft_log_level_from_string(), nft_log_level_is_noisier_than(), and nft_log_level_to_string().

#define NFT_LOG_PERROR (   msg)    nft_log(L_ERROR, __FILE__, __func__, __LINE__, "%s: %s", $msg, strerror(errno))

perror logging-functionality

#define NFT_LOG_NULL (   ret)    { nft_log(L_NOISY, __FILE__, __func__, __LINE__, "NULL pointer received."); return ret; }

NULL pointer error-msg & return abrevation

#define NFT_TODO ( )    NFT_LOG(L_ERROR, "Not implemented, yet. Please tell developers that you need this.")

Typedef Documentation

typedef void( NftLogFunc) (void *userdata, NftLoglevel level, const char *file, const char *func, int line, const char *msg)

logging function that will be called for every log-message if registered with nft_log_func_register()

Enumeration Type Documentation

available loglevels (used by nft_log_level_set() and NFT_LOG()) (adjust also logger.c:_loglevel_names when adjusting this)

Enumerator
L_INVALID 

used to represent invalid loglevels

L_MAX 

placeholder - always at beginning of the list

L_VERY_NOISY 

"verynoisy" - very very noisy output - don't send this in bug reports ;)

L_NOISY 

"noisy" - jabberish or oftenly repeating notifications

L_DEBUG 

"debug" - internal working notifications

L_VERBOSE 

"verbose" - rough internal working

L_INFO 

"info" - notification that's informative to the user but not vital

L_NOTICE 

"notice" - notfication the user should read

L_WARNING 

"warning" - only print warnings & errors

L_ERROR 

"error" - only important errors are printed

L_QUIET 

"quiet" - use wants no messages to be printed

L_MIN 

Function Documentation

void nft_log ( NftLoglevel  level,
const char *  file,
const char *  func,
int  line,
const char *  msg,
  ... 
)

main logging function

Note
DON'T CALL FUNCTION DIRECTLY! - Use the NFT_LOG() macro instead!
Parameters
[in]levelNftLoglevel this message should have
[in]fileFILE
[in]funcFUNC
[in]lineline
[in]msgthe log-message to output

References L_DEBUG, nft_log_level_get(), and nft_log_va().

void nft_log_va ( NftLoglevel  level,
const char *  file,
const char *  func,
int  line,
const char *  msg,
va_list  args 
)

va_list version of nft_log

Parameters
[in]levelNftLoglevel this message should have
[in]fileFILE
[in]funcFUNC
[in]lineline
[in]msgthe log-message to output
[in]argsva_list arguments

References L_WARNING, MAX_MSG_SIZE, and nft_log_level_to_string().

Referenced by nft_log().

void nft_log_func_register ( NftLogFunc func,
void *  userdata 
)

register an external logging function

Parameters
[in]funca NftLogFunc that should output a string to the user in some way
[in]userdataarbitrary pointer that will be passed to the NftLogFunc
NftResult nft_log_level_set ( NftLoglevel  loglevel)

set current loglevel

Parameters
[in]loglevelcurrent NftLoglevel
Returns
NFT_SUCCESS or NFT_FAILURE
Todo:
lock for threading

References L_INVALID, L_MAX, L_MIN, NFT_FAILURE, NFT_LOG_ENV_LEVEL, nft_log_level_from_string(), and NFT_SUCCESS.

NftLoglevel nft_log_level_get ( )

get current loglevel

Returns
the current NftLoglevel

References L_MAX, L_MIN, NFT_LOG_ENV_LEVEL, and nft_log_level_from_string().

Referenced by nft_log().

const char * nft_log_level_to_string ( NftLoglevel  loglevel)

return name of current loglevel

Parameters
[in]loglevelloglevel
Returns
string with loglevel name or NULL upon error

References L_ERROR, L_MAX, L_MIN, and NFT_LOG.

Referenced by nft_log_print_loglevels(), and nft_log_va().

NftLoglevel nft_log_level_from_string ( const char *  name)

return loglevel of loglevel-name

Parameters
[in]namestring with lowercase loglevel-name
Returns
loglevel or -1 upon error

References L_ERROR, L_INVALID, L_MAX, L_MIN, and NFT_LOG.

Referenced by nft_log_level_get(), and nft_log_level_set().

bool nft_log_level_is_noisier_than ( NftLoglevel  a,
NftLoglevel  b 
)

find out if loglevel a is more noisy than loglevel b

Parameters
[in]aNftLoglevel
[in]bNftLoglevel
Returns
true if a is more noisy than b, false if not or if loglevels are equal

References L_ERROR, L_MAX, L_MIN, and NFT_LOG.

void nft_log_print_loglevels ( )

print list of valid loglevel names to stdout

Returns
print list of loglevels to stdout

References L_MAX, L_MIN, and nft_log_level_to_string().