Add utilities and documentation
Add portable filesize and logging C libraries and documentation for development.
This commit is contained in:
parent
724659b25f
commit
d460a7ca93
12 changed files with 627 additions and 283806 deletions
102
src/logging/logging.c
Executable file
102
src/logging/logging.c
Executable file
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* @author : Aidan Mullen (git@acm.contact)
|
||||
* @file : logging
|
||||
* @created : Sunday Mar 24, 2024 10:05:35 EDT
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
#define VERSION "0.1.0-a.1"
|
||||
|
||||
#define TIME_BUF 64
|
||||
|
||||
char *note; /* Store note for logged actions. */
|
||||
time_t cur;
|
||||
|
||||
/*
|
||||
* Currently copies version number into the version variable; the version
|
||||
* number should be stored in a .INI file.
|
||||
*/
|
||||
|
||||
/* TODO: make struct for opening log file and appending. */
|
||||
|
||||
/* A new log file should be used for each day. */
|
||||
|
||||
/*
|
||||
* =============
|
||||
* Log and Print
|
||||
* =============
|
||||
*/
|
||||
|
||||
void flog(char *note)
|
||||
{
|
||||
FILE *logfile = fopen("log", "a");
|
||||
|
||||
/*char *timef = ctime(&cur);*/
|
||||
/*char *timen = strtok(ctime(&cur), "\r\n");*/
|
||||
|
||||
char stime[TIME_BUF]; /* Max length of date is 64 by default. */
|
||||
|
||||
/* strcspn method to remove new line will not work for some reason. */
|
||||
time(&cur); /* Store time in cur. */
|
||||
|
||||
/* ctime -> time char */
|
||||
|
||||
/* Custom time string. */
|
||||
|
||||
strftime(stime, TIME_BUF, "[ %a %Y-%m-%d %X ]: ", localtime(&cur));
|
||||
|
||||
/*timef[strcspn(timef, "\r\n")] = '\0';*/
|
||||
/*printf("[ %s ]: %s\n", timef, note);
|
||||
fprintf(logfile, "[ %s ]: %s\n", timef, note);*/
|
||||
|
||||
printf("%s %s\n", stime, note);
|
||||
fprintf(logfile, "%s %s\n", stime, note);
|
||||
fclose(logfile);
|
||||
}
|
||||
|
||||
/*
|
||||
* ========
|
||||
* Log Only
|
||||
* ========
|
||||
*/
|
||||
|
||||
void sflog(char *note)
|
||||
{
|
||||
FILE *logfile = fopen("log", "a");
|
||||
|
||||
/* strcspn method to remove new line will not work for some reason. */
|
||||
time(&cur); /* Store time in cur. */
|
||||
/* ctime -> time char */
|
||||
fprintf(logfile, "[ %s ]: %s\n", ctime(&cur), note);
|
||||
fclose(logfile);
|
||||
}
|
||||
|
||||
/*
|
||||
* ==========
|
||||
* Create Log
|
||||
* ==========
|
||||
*/
|
||||
|
||||
void init_log(void) /* Will be used for logging in the future. */
|
||||
{
|
||||
FILE *logfile = fopen("log", "r");
|
||||
if (logfile == NULL)
|
||||
{
|
||||
printf("Creating new log...\n");
|
||||
fopen("log", "w");
|
||||
flog("New log created");
|
||||
}
|
||||
flog("Logging started.");
|
||||
/*flog(strncat("Version: ", VERSION, sizeof(VERSION)));*/
|
||||
flog(VERSION);
|
||||
|
||||
fclose(logfile);
|
||||
}
|
||||
|
||||
/* --- end of LOGGING_C --- */
|
||||
Loading…
Add table
Add a link
Reference in a new issue