Compare commits
4 Commits
cfaae5529e
...
a276e644a7
| Author | SHA1 | Date | |
|---|---|---|---|
| a276e644a7 | |||
| 52f80fdbd7 | |||
| 406fe36977 | |||
| 14950e5937 |
@@ -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 */
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
@@ -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()");
|
||||||
|
|||||||
@@ -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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user