FOSSology  4.4.0
Open Source License Compliance by Open Source Software
logging.c File Reference

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>
Include dependency graph for logging.c:

Go to the source code of this file.

Classes

struct  log_event_args
 

Functions

static void log_event (scheduler_t *scheduler, log_event_args *pass)
 
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 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,...)
 

Variables

log_tmain_log = NULL
 

Detailed Description

Log related operations.

Definition in file logging.c.

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_event()

static void log_event ( scheduler_t scheduler,
log_event_args pass 
)
static

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
schedulerRelated scheduler reference
passthe 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_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 = NULL

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.