feat: add simple logging library
This commit is contained in:
@ -3,23 +3,25 @@
|
||||
#include <stdio.h>
|
||||
#include "optional.h"
|
||||
|
||||
struct cli_options {
|
||||
typedef struct {
|
||||
optional_str file;
|
||||
int verbosity;
|
||||
bool help;
|
||||
bool version;
|
||||
};
|
||||
bool use_colors;
|
||||
optional_str log_file;
|
||||
} cli_options;
|
||||
|
||||
// Construct a new cli_options struct instance.
|
||||
struct cli_options new_options();
|
||||
cli_options new_options();
|
||||
|
||||
// Delete a cli_options struct instance.
|
||||
void free_options(struct cli_options v);
|
||||
void free_options(cli_options v);
|
||||
|
||||
// Print the help message.
|
||||
void print_help(FILE * out, char* prog_name);
|
||||
|
||||
// Parse the command line arguments and give a new cli_options struct instance.
|
||||
struct cli_options parse(int argc, char** argv);
|
||||
cli_options parse(int argc, char** argv);
|
||||
|
||||
#endif
|
||||
|
28
include/log.h
Normal file
28
include/log.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef SCI_LOG_H
|
||||
#define SCI_LOG_H
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// TODO: Thread safety!
|
||||
enum {
|
||||
LOG_TRACE = 4,
|
||||
LOG_INFO = 3,
|
||||
LOG_WARN = 2,
|
||||
LOG_ERROR = 1,
|
||||
LOG_NOTHING = 0
|
||||
};
|
||||
typedef struct {
|
||||
int level;
|
||||
bool use_colors;
|
||||
FILE* out_file;
|
||||
} log_settings;
|
||||
|
||||
void log_log(const char* file, int line, int level, const char* fmt, ...);
|
||||
void log_init(log_settings settings);
|
||||
|
||||
#define log_trace(...) log_log(__FILE__, __LINE__, LOG_TRACE, __VA_ARGS__)
|
||||
#define log_info(...) log_log( __FILE__, __LINE__, LOG_INFO, __VA_ARGS__)
|
||||
#define log_warn(...) log_log( __FILE__, __LINE__, LOG_WARN, __VA_ARGS__)
|
||||
#define log_error(...) log_log(__FILE__, __LINE__, LOG_ERROR, __VA_ARGS__)
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user