FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
logging.h File Reference

Log related operations. More...

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>
#include <libpq-fe.h>
#include <glib.h>
Include dependency graph for logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  log_t
 

Macros

#define SCHE_PRONAME   "scheduler"
 
#define FATAL(...)
 
#define THREAD_FATAL(file, ...)
 
#define ERROR(...)
 
#define PQ_ERROR(pg_r, ...)
 
#define TEST_NOTIFY   verbose > 0
 
#define NOTIFY(...)
 
#define TEST_WARNING   verbose > 1
 
#define WARNING(...)
 
#define TVERB_JOB   (verbose & 0x8)
 
#define TVERB_AGENT   (verbose & 0x10)
 
#define TVERB_SCHED   (verbose & 0x20)
 
#define TVERB_EVENT   (verbose & 0x40)
 
#define TVERB_INTER   (verbose & 0x80)
 
#define TVERB_DATAB   (verbose & 0x100)
 
#define TVERB_HOST   (verbose & 0x200)
 
#define TVERB_SPECIAL   (verbose & 0x400)
 
#define V_JOB(...)   if(TVERB_JOB) log_printf(__VA_ARGS__)
 
#define V_AGENT(...)   if(TVERB_AGENT) log_printf(__VA_ARGS__)
 
#define V_SCHED(...)   if(TVERB_SCHED) log_printf(__VA_ARGS__)
 
#define V_EVENT(...)   if(TVERB_EVENT) log_printf(__VA_ARGS__)
 
#define V_INTERFACE(...)   if(TVERB_INTER) con_printf(main_log, __VA_ARGS__)
 
#define V_DATABASE(...)   if(TVERB_DATAB) log_printf(__VA_ARGS__)
 
#define V_HOST(...)   if(TVERB_HOST) log_printf(__VA_ARGS__)
 
#define V_SPECIAL(...)   if(TVERB_SPECIAL) log_printf(__VA_ARGS__)
 
#define log_printf(...)   lprintf(main_log, __VA_ARGS__)
 
#define con_printf(log, ...)   clprintf(log, __FILE__, __LINE__, __VA_ARGS__)
 

Functions

log_tlog_new (gchar *log_name, gchar *pro_name, pid_t pro_pid)
 Creates a new log. More...
 
log_tlog_new_FILE (FILE *log_file, gchar *log_name, gchar *pro_name, pid_t pro_pid)
 Creates a log file structure based on an already created FILE*. More...
 
void log_destroy (log_t *log)
 Free memory associated with the log file. More...
 
int lprintf (log_t *log, const char *fmt,...)
 Main logging function. More...
 
int clprintf (log_t *log, char *s_name, uint16_t s_line, const char *fmt,...)
 
int vlprintf (log_t *log, const char *fmt, va_list args)
 The provides the same functionality for lprintf as vprintf does for printf. More...
 

Variables

log_tmain_log
 

Detailed Description

Log related operations.

Definition in file logging.h.

Macro Definition Documentation

#define ERROR (   ...)
Value:
do { \
lprintf(main_log, "ERROR %s.%d: ", __FILE__, __LINE__); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "\n"); } while(0)
log_t * main_log
Definition: logging.c:44
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
Definition: logging.c:191

Macro that is called when any type of error is generated

Definition at line 90 of file logging.h.

#define FATAL (   ...)
Value:
do { \
lprintf(main_log, "FATAL %s.%d: ", __FILE__, __LINE__); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "FATAL errno is: %s\n", strerror(errno)); \
exit(-2); } while(0)
log_t * main_log
Definition: logging.c:44
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
Definition: logging.c:191

Macro that is called when the scheduler hits a fatal error

Definition at line 74 of file logging.h.

#define NOTIFY (   ...)
Value:
if(TEST_NOTIFY) do { \
lprintf(main_log, "NOTE: "); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "\n"); } while(0)
log_t * main_log
Definition: logging.c:44
#define TEST_NOTIFY
Definition: logging.h:104
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
Definition: logging.c:191

Definition at line 105 of file logging.h.

#define PQ_ERROR (   pg_r,
  ... 
)
Value:
{ \
lprintf(main_log, "ERROR %s.%d: ", __FILE__, __LINE__); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "ERROR postgresql error: %s\n", PQresultErrorMessage(pg_r)); } \
log_t * main_log
Definition: logging.c:44
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
Definition: logging.c:191
#define SafePQclear(pgres)
Definition: scheduler.h:140

Macro that is called when any type of postgresql error is generated

Definition at line 96 of file logging.h.

#define TEST_NOTIFY   verbose > 0

Macros that is called when a notification is generated

Definition at line 104 of file logging.h.

#define TEST_WARNING   verbose > 1

Macros that is called when any type of warning is generated

Definition at line 111 of file logging.h.

#define THREAD_FATAL (   file,
  ... 
)
Value:
do { \
con_printf(file, "THREAD_FATAL %s.%d: ", __FILE__, __LINE__); \
con_printf(file, __VA_ARGS__); \
con_printf(file, "\n"); \
con_printf(file, "THREAD_FATAL errno is: %s\n", strerror(errno)); \
g_thread_exit(NULL); } while(0)

Macro that is called when a thread generated a fatal error

Definition at line 82 of file logging.h.

#define WARNING (   ...)
Value:
if(TEST_WARNING) do { \
lprintf(main_log, "WARNING %s.%d: ", __FILE__, __LINE__); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "\n"); } while(0)
#define TEST_WARNING
Definition: logging.h:111
log_t * main_log
Definition: logging.c:44
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
Definition: logging.c:191

Definition at line 112 of file logging.h.

Function Documentation

int clprintf ( log_t log,
char *  s_name,
uint16_t  s_line,
const char *  fmt,
  ... 
)

Function that allows for printing to the log file concurrently. This will create an event that prints the log file instead of printing it itself. This does have the disadvantage that two call of clprintf right next to each other will not necessarily fall next to each other in the log.

Parameters
logThe log to print to
s_nameName of the source file printing the log
s_lineLine number of the source file
fmtThe format string like any normal printf function
Returns
If the printf was successful.

Definition at line 281 of file logging.c.

void log_destroy ( log_t log)

Free memory associated with the log file.

Parameters
logthe log file to close

Definition at line 161 of file logging.c.

log_t* log_new ( gchar *  log_name,
gchar *  pro_name,
pid_t  pro_pid 
)

Creates a new log.

This will open and set the parameters of a log_t type. This checks the name given and checks if it is a directory. If it is a directory, it will try to open a file named fossology.log inside the directory instead. If the file cannot be opened, this will return NULL.

Parameters
log_nameThe name or directory of the log file
pro_nameThe name of the process printed to the log file, can be NULL
pro_pidThe pid of the process that this log file belongs to
Returns
A new log_t structure

Definition at line 92 of file logging.c.

log_t* log_new_FILE ( FILE *  log_file,
gchar *  log_name,
gchar *  pro_name,
pid_t  pro_pid 
)

Creates a log file structure based on an already created FILE*.

Parameters
log_fileThe already existing FILE*
log_nameThe name or directory of the log file
pro_nameThe name of the process to write to the log file
pro_pidThe PID of the process to write to the log file
Returns
A new log_t instance that can be used to write to

Definition at line 137 of file logging.c.

int lprintf ( log_t log,
const char *  fmt,
  ... 
)

Main logging function.

This will print the time stamp for the log and the scheduler's pid, followed by whatever is to be printed to the log. This function will also make sure that the log is open, and if it isn't open it using whatever the log_name is currently set to. This should be used almost identically to a normal printf

Parameters
logThe log to print to
fmtThe format for the printed data
Returns
1 on success, 0 otherwise

Definition at line 191 of file logging.c.

int vlprintf ( log_t log,
const char *  fmt,
va_list  args 
)

The provides the same functionality for lprintf as vprintf does for printf.

If somebody wanted to create a custom logging function, they could simply use this function within a va_start va_end pair.

Parameters
logThe log to print to
fmtThe formatting string for the print
argsThe arguemtn for the print in and form of a va_list
Returns
1 on success, 0 otherwise

Definition at line 224 of file logging.c.

Variable Documentation

log_t* main_log

The main log, this is global because every function within the scheduler should have access to the main log.

Definition at line 44 of file logging.c.