12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "render.h"
- #include "terminal.h"
- /* Log level guideline:
- * - ZF_LOG_FATAL - happened something impossible and absolutely unexpected.
- * Process can't continue and must be terminated.
- * Example: division by zero, unexpected modifications from other thread.
- * - ZF_LOG_ERROR - happened something possible, but highly unexpected. The
- * process is able to recover and continue execution.
- * Example: out of memory (could also be FATAL if not handled properly).
- * - ZF_LOG_WARN - happened something that *usually* should not happen and
- * significantly changes application behavior for some period of time.
- * Example: configuration file not found, auth error.
- * - ZF_LOG_INFO - happened significant life cycle event or major state
- * transition.
- * Example: app started, user logged in.
- * - ZF_LOG_DEBUG - minimal set of events that could help to reconstruct the
- * execution path. Usually disabled in release builds.
- * - ZF_LOG_VERBOSE - all other events. Usually disabled in release builds.
- *
- * *Ideally*, log file of debugged, well tested, production ready application
- * should be empty or very small. Choosing a right log level is as important as
- * providing short and self descriptive log message.
- */
- /*
- #define ZF_LOG_VERBOSE 1
- #define ZF_LOG_DEBUG 2
- #define ZF_LOG_INFO 3
- #define ZF_LOG_WARN 4
- #define ZF_LOG_ERROR 5
- #define ZF_LOG_FATAL 6
- */
- // LOGGING with file output
- #include "zf_log.h"
- FILE *g_log_file;
- static void file_output_callback(const zf_log_message *msg, void *arg) {
- (void)arg;
- *msg->p = '\n';
- fwrite(msg->buf, msg->p - msg->buf + 1, 1, g_log_file);
- fflush(g_log_file);
- }
- static void file_output_close(void) { fclose(g_log_file); }
- static void file_output_open(const char *const log_path) {
- g_log_file = fopen(log_path, "a");
- if (!g_log_file) {
- ZF_LOGW("Failed to open log file %s", log_path);
- return;
- }
- atexit(file_output_close);
- zf_log_set_output_v(ZF_LOG_PUT_STD, 0, file_output_callback);
- }
- struct console_details console;
- int main(int argc, char *argv[]) {
- file_output_open("render.log");
- render(1, "^P2HELLO^P3 THERE^P2\n", 22);
- render(1, "^P2^Fbat.^P1\n^P1OK.\n", 21);
- return 0;
- }
|