implemented logFile type in logger.c
This commit is contained in:
parent
1e7868ead1
commit
e2c5791dc7
@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <why2/logger/flags.h>
|
#include <why2/logger/flags.h>
|
||||||
|
|
||||||
int initLogger(char *directoryPath)
|
logFile initLogger(char *directoryPath)
|
||||||
{
|
{
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -37,7 +37,7 @@ int initLogger(char *directoryPath)
|
|||||||
time_t timeL = time(NULL);
|
time_t timeL = time(NULL);
|
||||||
struct tm tm = *localtime(&timeL);
|
struct tm tm = *localtime(&timeL);
|
||||||
int buffer = 1;
|
int buffer = 1;
|
||||||
int returning;
|
int file;
|
||||||
char *filePath = malloc(strlen(directoryPath) + 1 + strlen(LOG_FORMAT) + 1);
|
char *filePath = malloc(strlen(directoryPath) + 1 + strlen(LOG_FORMAT) + 1);
|
||||||
char *dateBuffer = malloc(strlen(LOG_FORMAT_START) + 1);
|
char *dateBuffer = malloc(strlen(LOG_FORMAT_START) + 1);
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
@ -60,18 +60,29 @@ int initLogger(char *directoryPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer > MAX_USAGE) return INVALID_FILE; //MAX_USAGE WAS REACHED
|
if (buffer > MAX_USAGE) //MAX_USAGE WAS REACHED
|
||||||
|
{
|
||||||
|
file = INVALID_FILE;
|
||||||
|
|
||||||
|
goto deallocation;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(filePath, LOG_FORMATTING, directoryPath, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, buffer); //GENERATE LOG-NAME
|
sprintf(filePath, LOG_FORMATTING, directoryPath, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, buffer); //GENERATE LOG-NAME
|
||||||
|
|
||||||
returning = open(filePath, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
file = open(filePath, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
|
|
||||||
|
deallocation:
|
||||||
|
|
||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
free(filePath);
|
free(filePath);
|
||||||
free(dateBuffer);
|
free(dateBuffer);
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
return returning;
|
return (logFile)
|
||||||
|
{
|
||||||
|
file,
|
||||||
|
filePath
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeLog(int loggerFile, char *logMessage)
|
void writeLog(int loggerFile, char *logMessage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user