Compare commits

...

4 Commits

Author SHA1 Message Date
a276e644a7 refactor: remove log_debug in main 2026-02-10 00:38:31 +01:00
52f80fdbd7 fix(debug): EVELOPER instead of DEVELOPER 2026-02-10 00:34:15 +01:00
406fe36977 chore(meson): back to c11 2026-02-10 00:32:34 +01:00
14950e5937 revert(debug): use macro 2026-02-10 00:32:24 +01:00
5 changed files with 52 additions and 39 deletions

View File

@@ -6,8 +6,8 @@
/* Configuration for static file serving */ /* Configuration for static file serving */
typedef struct cws_handler_config { typedef struct cws_handler_config {
const char *root_dir; /*< "www" */ const char *root_dir;
const char *index_file; /*< "index.html" */ const char *index_file;
} cws_handler_config_s; } cws_handler_config_s;
/* Static file handler */ /* Static file handler */

View File

@@ -21,11 +21,17 @@
#define _DEBUG "[DEBUG]" #define _DEBUG "[DEBUG]"
#endif #endif
void _cws_log_info_internal(const char *file, int line, const char *fmt, ...);
void _cws_log_warning_internal(const char *file, int line, const char *fmt, ...);
void _cws_log_error_internal(const char *file, int line, const char *fmt, ...);
void _cws_log_debug_internal(const char *file, int line, const char *fmt, ...);
#define cws_log_info(fmt, ...) _cws_log_info_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define cws_log_warning(fmt, ...) _cws_log_warning_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define cws_log_error(fmt, ...) _cws_log_error_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define cws_log_debug(fmt, ...) _cws_log_debug_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
void cws_log_init(void); void cws_log_init(void);
void cws_log_info(const char *fmt, ...);
void cws_log_debug(const char *fmt, ...);
void cws_log_warning(const char *fmt, ...);
void cws_log_error(const char *fmt, ...);
void cws_log_shutdown(void); void cws_log_shutdown(void);
#endif #endif

View File

@@ -2,7 +2,7 @@ project(
'cws', 'cws',
'c', 'c',
version: '0.1.0', version: '0.1.0',
default_options: ['c_std=c18', 'warning_level=3'], default_options: ['c_std=c11', 'warning_level=3'],
) )
cc = meson.get_compiler('c') cc = meson.get_compiler('c')

View File

@@ -14,7 +14,6 @@ void cws_signal_handler(int signo) {
int main(void) { int main(void) {
cws_log_init(); cws_log_init();
cws_log_debug("Starting cws");
if (signal(SIGINT, cws_signal_handler) == SIG_ERR) { if (signal(SIGINT, cws_signal_handler) == SIG_ERR) {
cws_log_error("signal()"); cws_log_error("signal()");

View File

@@ -1,65 +1,73 @@
#include "utils/debug.h" #include "utils/debug.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <sys/syslog.h> #include <syslog.h>
void cws_log_init(void) { void cws_log_init(void) {
openlog("cws", LOG_PID | LOG_CONS, LOG_DAEMON); openlog("cws", LOG_PID | LOG_CONS, LOG_DAEMON);
} }
void cws_log_info(const char *fmt, ...) { void _cws_log_info_internal(const char *file, int line, const char *fmt, ...) {
va_list args; va_list args;
fprintf(stdout, _INFO " "); fprintf(stdout, _INFO " [%s:%d] ", file, line);
va_start(args, fmt); va_start(args, fmt);
vfprintf(stdout, fmt, args); vfprintf(stdout, fmt, args);
va_end(args);
fprintf(stdout, "\n");
va_start(args, fmt);
syslog(LOG_INFO, fmt, args); syslog(LOG_INFO, fmt, args);
va_end(args); va_end(args);
fprintf(stdout, "\n");
} }
void cws_log_warning(const char *fmt, ...) { void _cws_log_warning_internal(const char *file, int line, const char *fmt, ...) {
va_list args; va_list args;
fprintf(stdout, _WARNING " "); fprintf(stdout, _WARNING " [%s:%d] ", file, line);
va_start(args, fmt); va_start(args, fmt);
vfprintf(stdout, fmt, args); vfprintf(stdout, fmt, args);
va_end(args); va_end(args);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
va_start(args, fmt);
syslog(LOG_WARNING, fmt, args);
va_end(args);
} }
void cws_log_error(const char *fmt, ...) { void _cws_log_error_internal(const char *file, int line, const char *fmt, ...) {
va_list args; va_list args;
fprintf(stdout, _ERR " "); fprintf(stdout, _ERR " [%s:%d] ", file, line);
va_start(args, fmt); va_start(args, fmt);
vfprintf(stdout, fmt, args); vfprintf(stdout, fmt, args);
va_end(args);
fprintf(stdout, "\n");
va_start(args, fmt);
syslog(LOG_ERR, fmt, args); syslog(LOG_ERR, fmt, args);
va_end(args);
}
#ifdef EVELOPER
void _cws_log_debug_internal(const char *file, int line, const char *fmt, ...) {
va_list args;
fprintf(stdout, _DEBUG " [%s:%d] ", file, line);
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args); va_end(args);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
va_start(args, fmt);
syslog(LOG_DEBUG, fmt, args);
va_end(args);
} }
#else
void _cws_log_debug_internal(const char *file, int line, const char *fmt, ...) {
(void)file;
(void)line;
(void)fmt;
/* Nothing */
}
#endif
void cws_log_shutdown(void) { void cws_log_shutdown(void) {
closelog(); closelog();
} }
#ifdef EVELOPER
void cws_log_debug(const char *fmt, ...) {
fprintf(stdout, _DEBUG " [%s:%d] ", __FILE__, __LINE__);
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
syslog(LOG_DEBUG, fmt, args);
va_end(args);
fprintf(stdout, "\n");
}
#else
void cws_log_debug(const char *fmt, ...) {
/* Nothing */
}
#endif