浏览代码

Improve logging

Use our logging mechanism and remove dependency on SDL.
master
父节点
当前提交
073ad235ae
共有 3 个文件被更改,包括 62 次插入7 次删除
  1. +2
    -2
      TODO.md
  2. +57
    -4
      src/packages/log/IZ_intercept.c
  3. +3
    -1
      src/packages/log/IZ_intercept.h

+ 2
- 2
TODO.md 查看文件

@@ -1,3 +1,5 @@
- [X] Improve logging (remove SDL/lws dependency)
- [ ] Unify memset/memcpy/free/malloc functions (remove SDL/lws dependency)
- [ ] Fix gamepad mapping
- [ ] Provide default mapping
- [ ] Allow customization of button mappings
@@ -5,5 +7,3 @@
- [ ] server
- [ ] client (frontend)
- [ ] Proof-of-concept for fast SVG rendering (we're going to use SVG instead of Spine)
- [ ] Improve logging (remove SDL/lws dependency)
- [ ] Unify memset/memcpy/free/malloc functions (remove SDL/lws dependency)

+ 57
- 4
src/packages/log/IZ_intercept.c 查看文件

@@ -1,22 +1,75 @@
#include "IZ_intercept.h"

typedef enum {
IZ_LOG_INTERCEPT_EXTRACT_STATE_INITIAL,
IZ_LOG_INTERCEPT_EXTRACT_STATE_OPEN_BRACKET,
IZ_LOG_INTERCEPT_EXTRACT_STATE_CLOSE_BRACKET,
IZ_LOG_INTERCEPT_EXTRACT_STATE_SPACE,
IZ_LOG_INTERCEPT_EXTRACT_STATE_MESSAGE,
} IZ_LogInterceptExtractState;

void IZ_LogInterceptExtractWSMessageToFormatted(const char* raw_line, char* formatted_line) {
IZ_LogInterceptExtractState state = IZ_LOG_INTERCEPT_EXTRACT_STATE_INITIAL;
unsigned int offset = 0;

IZ_memset(formatted_line, 0, 1024);
for (unsigned int i = 0; i < 1024; i += 1) {
if (state == IZ_LOG_INTERCEPT_EXTRACT_STATE_INITIAL && raw_line[i] == '[') {
state = IZ_LOG_INTERCEPT_EXTRACT_STATE_OPEN_BRACKET;
continue;
}

if (state == IZ_LOG_INTERCEPT_EXTRACT_STATE_OPEN_BRACKET && raw_line[i] == ']') {
state = IZ_LOG_INTERCEPT_EXTRACT_STATE_CLOSE_BRACKET;
continue;
}

if (state == IZ_LOG_INTERCEPT_EXTRACT_STATE_CLOSE_BRACKET && raw_line[i] == ' ') {
offset = i + 1;
state = IZ_LOG_INTERCEPT_EXTRACT_STATE_SPACE;
continue;
}

if (state == IZ_LOG_INTERCEPT_EXTRACT_STATE_SPACE) {
if (isspace(raw_line[i])) {
continue;
}
state = IZ_LOG_INTERCEPT_EXTRACT_STATE_MESSAGE;
}

if (raw_line[i] == '\r' || raw_line[i] == '\n' || raw_line[i] == '\0') {
formatted_line[i - offset] = '\0';
break;
}

if (iscntrl(raw_line[i])) {
continue;
}

formatted_line[i - offset] = raw_line[i];
}
}

void IZ_LogInterceptHandleFromWS(i32 level, const char* line) {
static char buffer[1024];
IZ_LogInterceptExtractWSMessageToFormatted(line, buffer);
switch (level) {
// TODO level is a bit field...check if each level is OR'd.
case LLL_ERR:
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", line);
IZ_LogError("%s", buffer);
return;
case LLL_WARN:
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "%s", line);
IZ_LogWarn(false, "%s", buffer);
return;
case LLL_NOTICE:
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s", line);
IZ_LogInfo(IZ_LOG_CATEGORY_GENERIC, "%s", buffer);
return;
case LLL_USER:
default:
break;
}

SDL_Log("%s", line);
IZ_Log("%s", buffer);
}

void IZ_LogInterceptWSMessages(i32 level) {


+ 3
- 1
src/packages/log/IZ_intercept.h 查看文件

@@ -1,9 +1,11 @@
#ifndef IZ_INTERCEPT_H
#define IZ_INTERCEPT_H

#include "SDL_log.h"
#include <ctype.h>
#include "libwebsockets.h"
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"
#include "IZ_log.h"

void IZ_LogInterceptWSMessages(i32);



正在加载...
取消
保存