1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-05 19:51:45 +00:00

rather call the files log.c and log.h

changed LOG_LEVEL order
export only externaly used functions
add todos
This commit is contained in:
Resaec 2018-09-23 23:18:41 +02:00
parent 840242b68e
commit 7548c8ecfa
No known key found for this signature in database
GPG key ID: 5E890BD898EA9064
3 changed files with 120 additions and 96 deletions

View file

@ -0,0 +1,104 @@
/*
* Copyright (c) 2018 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "log.h"
#include "display/video_fb.h"
/* default log level for screen output */
ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_MANDATORY;
void log_set_log_level(ScreenLogLevel log_level) {
g_screen_log_level = log_level;
}
void log_to_uart(const char *message) {
/* TODO: add UART logging */
}
void print_to_screen(ScreenLogLevel screenLogLevel, char *message) {
/* don't print to screen if below log level */
if(g_screen_log_level == SCREEN_LOG_LEVEL_NONE || screenLogLevel > g_screen_log_level) return;
//video_puts(buf);
printf(message);
}
/**
* vprintk - logs a message to the console
*
* This text will not be colored or prefixed but logged to UART
* UART is TODO
*/
void vprint(ScreenLogLevel screenLogLevel, const char *fmt, va_list args)
{
char buf[PRINT_MESSAGE_MAX_LENGTH];
vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, fmt, args);
/* log to UART */
log_to_uart(buf);
print_to_screen(screenLogLevel, buf);
}
/**
* print - logs a message and prints it to screen based on its screenLogLevel
*
* If the level is below g_screen_log_level it will not be shown but logged to UART
* UART is TODO
*/
void print(ScreenLogLevel screenLogLevel, const char * fmt, ...)
{
char typebuf[] = "[%s] %s";
char buf[PRINT_MESSAGE_MAX_LENGTH] = {};
char message[PRINT_MESSAGE_MAX_LENGTH] = {};
/* apply prefix and append message format */
/* TODO: add coloring to the output */
/* TODO: make splash disappear if level > MANDATORY */
switch(screenLogLevel)
{
case SCREEN_LOG_LEVEL_ERROR:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "ERROR", fmt);
break;
case SCREEN_LOG_LEVEL_WARNING:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "WARNING", fmt);
break;
case SCREEN_LOG_LEVEL_MANDATORY:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt);
break;
case SCREEN_LOG_LEVEL_INFO:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "INFO", fmt);
break;
case SCREEN_LOG_LEVEL_DEBUG:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "DEBUG", fmt);
break;
default:
break;
}
/* input arguments */
va_list args;
va_start(args, fmt);
vsnprintf(message, PRINT_MESSAGE_MAX_LENGTH, buf, args);
va_end(args);
/* log to UART */
log_to_uart(message);
print_to_screen(screenLogLevel, message);
}

View file

@ -19,20 +19,24 @@
#define PRINT_MESSAGE_MAX_LENGTH 512 #define PRINT_MESSAGE_MAX_LENGTH 512
typedef enum { //#include <stdint.h>
PRINT_LOG_DEBUG = 0,
PRINT_LOG_INFO,
PRINT_LOG_MANDATORY,
PRINT_LOG_WARNING,
PRINT_LOG_ERROR
} PrintLogLevel;
#include <stdint.h>
#include "../../fusee-primary/src/lib/vsprintf.h" #include "../../fusee-primary/src/lib/vsprintf.h"
extern PrintLogLevel g_print_log_level; typedef enum {
SCREEN_LOG_LEVEL_NONE = 0,
SCREEN_LOG_LEVEL_ERROR = 1,
SCREEN_LOG_LEVEL_WARNING = 2,
SCREEN_LOG_LEVEL_MANDATORY = 3, /* no log prefix */
SCREEN_LOG_LEVEL_INFO = 4,
SCREEN_LOG_LEVEL_DEBUG = 5
} ScreenLogLevel;
//void vprintk(const char *fmt, va_list args); /* TODO: make this configurable by BCT.ini */
void print(PrintLogLevel printLogLevel, const char* fmt, ...); extern ScreenLogLevel g_screen_log_level;
void log_set_log_level(ScreenLogLevel screen_log_level);
void log_to_uart(const char *message);
void vprint(ScreenLogLevel screenLogLevel, const char *fmt, va_list args);
void print(ScreenLogLevel screenLogLevel, const char* fmt, ...);
#endif #endif

View file

@ -1,84 +0,0 @@
/*
* Copyright (c) 2018 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "print.h"
#include "display/video_fb.h"
PrintLogLevel g_print_log_level = PRINT_LOG_DEBUG;
void vprintk(const char *fmt, va_list args)
{
char buf[PRINT_MESSAGE_MAX_LENGTH];
vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, fmt, args);
video_puts(buf);
}
void printk(const char *fmt, ...)
{
va_list list;
va_start(list, fmt);
vprintk(fmt, list);
va_end(list);
}
/**
* print - logs a message based on its message_level
*
* If the level is below g_message_level it will not be shown
* but logged to UART (UART is TO DO)
*/
void print(PrintLogLevel printLogLevel, const char * fmt, ...)
{
char typebuf[] = "[%s] %s";
char buf[PRINT_MESSAGE_MAX_LENGTH] = {};
/* apply prefix and append message format */
/* TODO: add coloring to the output */
switch(printLogLevel)
{
case PRINT_LOG_DEBUG:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "DEBUG", fmt);
break;
case PRINT_LOG_INFO:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "INFO", fmt);
break;
case PRINT_LOG_MANDATORY:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt);
break;
case PRINT_LOG_WARNING:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "WARNING", fmt);
break;
case PRINT_LOG_ERROR:
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "ERROR", fmt);
break;
default:
break;
}
/* input arguments for UART logging */
va_list args;
va_start(args, fmt);
vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, buf, args);
va_end(args);
/* TODO: implement SD and/or UART logging */
/* don't print to screen if below log level */
if (printLogLevel < g_print_log_level) return;
printk(buf);
}