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>
Go to the source code of this file.
|
#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__) |
|
|
log_t * | log_new (gchar *log_name, gchar *pro_name, pid_t pro_pid) |
| Creates a new log. More...
|
|
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*. 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...
|
|
Log related operations.
Definition in file logging.h.
◆ ERROR
Value: do { \
lprintf(
main_log,
"ERROR %s.%d: ", __FILE__, __LINE__); \
Macro that is called when any type of error is generated
Definition at line 79 of file logging.h.
◆ FATAL
Value: do { \
lprintf(
main_log,
"FATAL %s.%d: ", __FILE__, __LINE__); \
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
◆ PQ_ERROR
#define PQ_ERROR |
( |
|
pg_r, |
|
|
|
... |
|
) |
| |
Value: { \
lprintf(
main_log,
"ERROR %s.%d: ", __FILE__, __LINE__); \
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
Macros that is called when a notification is generated
Definition at line 93 of file logging.h.
◆ TEST_WARNING
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
Value:
lprintf(
main_log,
"WARNING %s.%d: ", __FILE__, __LINE__); \
Definition at line 101 of file logging.h.
◆ 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
-
log | The log to print to |
s_name | Name of the source file printing the log |
s_line | Line number of the source file |
fmt | The 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
-
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_name | The name or directory of the log file |
pro_name | The name of the process printed to the log file, can be NULL |
pro_pid | The 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_file | The already existing FILE* |
log_name | The name or directory of the log file |
pro_name | The name of the process to write to the log file |
pro_pid | The 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
-
log | The log to print to |
fmt | The 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
-
log | The log to print to |
fmt | The formatting string for the print |
args | The 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.
◆ main_log
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.