Log related operations.
More...
#include <event.h>
#include <logging.h>
#include <scheduler.h>
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <glib.h>
Go to the source code of this file.
|
static void | log_event (scheduler_t *scheduler, log_event_args *pass) |
|
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 | vlprintf (log_t *log, const char *fmt, va_list args) |
| The provides the same functionality for lprintf as vprintf does for printf. More...
|
|
int | clprintf (log_t *log, char *s_name, uint16_t s_line, const char *fmt,...) |
|
Log related operations.
Definition in file logging.c.
◆ 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_event()
Event used to pass log messages to the main thread for processing instead of processing them in a side thread. This is used so that prints will happen in the correct order instead of intermixed.
- Parameters
-
scheduler | Related scheduler reference |
pass | the arguments for the event |
Definition at line 57 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.