Demonstrates how to work with a function target.
Demonstrates how to work with a function target.
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int red_count = 0;
int green_count = 0;
int blue_count = 0;
int
const char *color;
int result;
if( strcmp( color, "red" ) == 0 ) {
result = ++red_count;
} else if( strcmp( color, "green" ) == 0 ) {
result = ++green_count;
} else if( strcmp( color, "blue" ) == 0 ) {
result = ++blue_count;
} else {
result = -1;
}
free( ( void * ) color );
return result;
}
int
main( void ) {
int i;
const char *ball_colors[] = {"red", "green" , "blue"};
const char *color;
STUMPLESS_SEVERITY_INFO,
"ball-processing-machine",
"processed-ball",
"a ball has finished processing" );
srand( time( NULL ) );
for( i = 0; i < 1024; i++ ) {
color = ball_colors[rand( ) % 3];
}
printf( "red ball count: %d\n", red_count );
printf( "green ball count: %d\n", green_count );
printf( "blue ball count: %d\n", blue_count );
return EXIT_SUCCESS;
}
STUMPLESS_PUBLIC_FUNCTION void stumpless_destroy_entry_and_contents(const struct stumpless_entry *entry)
Destroys an entry as well as all elements and params that it contains, freeing any allocated memory.
STUMPLESS_PUBLIC_FUNCTION const char * stumpless_get_entry_param_value_by_name(const struct stumpless_entry *entry, const char *element_name, const char *param_name)
Gets the value of the first param from the element with the given name in an entry.
STUMPLESS_PUBLIC_FUNCTION struct stumpless_entry * stumpless_new_entry(enum stumpless_facility facility, enum stumpless_severity severity, const char *app_name, const char *msgid, const char *message,...)
Creates a new entry with the given characteristics.
STUMPLESS_PUBLIC_FUNCTION struct stumpless_entry * stumpless_set_entry_param_value_by_name(struct stumpless_entry *entry, const char *element_name, const char *param_name, const char *value)
Sets the value of the first param in the named element an entry.
STUMPLESS_PUBLIC_FUNCTION void stumpless_close_function_target(const struct stumpless_target *target)
Closes a function target.
STUMPLESS_PUBLIC_FUNCTION struct stumpless_target * stumpless_open_function_target(const char *name, stumpless_log_func_t log_function)
Opens a function target.
STUMPLESS_PUBLIC_FUNCTION void stumpless_free_all(void)
Closes the default target if it has been opened, frees all memory allocated internally,...
A log entry.
Definition entry.h:60
A target that log entries can be sent to.
Definition target.h:140
The main header file for the stumpless logging library.
STUMPLESS_PUBLIC_FUNCTION int stumpless_add_entry(struct stumpless_target *target, const struct stumpless_entry *entry)
Adds an entry into a given target.