FOSSology  4.4.0
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

◆ ERROR

#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:33

Macro that is called when any type of error is generated

Definition at line 79 of file logging.h.

◆ FATAL

#define FATAL (   ...)
Value:
do { \
lprintf(main_log, "FATAL %s.%d: ", __FILE__, __LINE__); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "\n"); \
lprintf(main_log, "FATAL errno is: %s\n", strerror(errno)); \
exit(-2); } while(0)

Macro that is called when the scheduler hits a fatal error

Definition at line 63 of file logging.h.

◆ NOTIFY

#define NOTIFY (   ...)
Value:
if(TEST_NOTIFY) do { \
lprintf(main_log, "NOTE: "); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "\n"); } while(0)
#define TEST_NOTIFY
Definition: logging.h:93

Definition at line 94 of file logging.h.

◆ PQ_ERROR

#define PQ_ERROR (   pg_r,
  ... 
)
Value:
{ \
lprintf(main_log, "ERROR %s.%d: ", __FILE__, __LINE__); \
lprintf(main_log, __VA_ARGS__); \
lprintf(main_log, "\n"); \
lprintf(main_log, "ERROR postgresql error: %s\n", PQresultErrorMessage(pg_r)); } \
SafePQclear(pg_r)

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

Definition at line 85 of file logging.h.

◆ TEST_NOTIFY

#define TEST_NOTIFY   verbose > 0

Macros that is called when a notification is generated

Definition at line 93 of file logging.h.

◆ TEST_WARNING

#define TEST_WARNING   verbose > 1

Macros that is called when any type of warning is generated

Definition at line 100 of file logging.h.

◆ THREAD_FATAL

#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 71 of file logging.h.

◆ WARNING

#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:100

Definition at line 101 of file logging.h.

Function Documentation

◆ clprintf()

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 270 of file logging.c.

◆ log_destroy()

void log_destroy ( log_t log)

Free memory associated with the log file.

Parameters
logthe log file to close

Definition at line 150 of file logging.c.

◆ log_new()

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 81 of file logging.c.

◆ log_new_FILE()

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 126 of file logging.c.

◆ lprintf()

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 180 of file logging.c.

◆ vlprintf()

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 213 of file logging.c.

Variable Documentation

◆ main_log

log_t* main_log
extern

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

Definition at line 33 of file logging.c.