mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-04 20:15:09 +01:00
Fix logging
This commit is contained in:
parent
54618b3cac
commit
3e1d862aff
@ -27,7 +27,7 @@
|
||||
/// \brief Log level
|
||||
enum LogLevel
|
||||
{
|
||||
DEBUG,
|
||||
DEBUGLOG,
|
||||
INFO,
|
||||
ERROR,
|
||||
COMMAND,
|
||||
|
@ -50,7 +50,7 @@ bool s_logUpdated = true;
|
||||
|
||||
/// \brief Message prefix
|
||||
static char const *const s_prefix[] = {
|
||||
[DEBUG] = "[DEBUG]",
|
||||
[DEBUGLOG] = "[DEBUG]",
|
||||
[INFO] = "[INFO]",
|
||||
[ERROR] = "[ERROR]",
|
||||
[COMMAND] = "[COMMAND]",
|
||||
@ -114,7 +114,7 @@ void drawLog ()
|
||||
|
||||
#ifdef CLASSIC
|
||||
char const *const s_colors[] = {
|
||||
[DEBUG] = "\x1b[33;1m", // yellow
|
||||
[DEBUGLOG] = "\x1b[33;1m", // yellow
|
||||
[INFO] = "\x1b[37;1m", // white
|
||||
[ERROR] = "\x1b[31;1m", // red
|
||||
[COMMAND] = "\x1b[32;1m", // green
|
||||
@ -204,7 +204,7 @@ void debug (char const *const fmt_, ...)
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, fmt_);
|
||||
addLog (DEBUG, fmt_, ap);
|
||||
addLog (DEBUGLOG, fmt_, ap);
|
||||
va_end (ap);
|
||||
#endif
|
||||
}
|
||||
|
42
source/wiiu/logger.c
Normal file
42
source/wiiu/logger.c
Normal file
@ -0,0 +1,42 @@
|
||||
#ifdef DEBUG
|
||||
#include <stdint.h>
|
||||
#include <whb/log_cafe.h>
|
||||
#include <whb/log_module.h>
|
||||
#include <whb/log_udp.h>
|
||||
|
||||
uint32_t moduleLogInit = false;
|
||||
uint32_t cafeLogInit = false;
|
||||
uint32_t udpLogInit = false;
|
||||
#endif // DEBUG
|
||||
|
||||
void initLogging ()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (!(moduleLogInit = WHBLogModuleInit ()))
|
||||
{
|
||||
cafeLogInit = WHBLogCafeInit ();
|
||||
udpLogInit = WHBLogUdpInit ();
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
void deinitLogging ()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (moduleLogInit)
|
||||
{
|
||||
WHBLogModuleDeinit ();
|
||||
moduleLogInit = false;
|
||||
}
|
||||
if (cafeLogInit)
|
||||
{
|
||||
WHBLogCafeDeinit ();
|
||||
cafeLogInit = false;
|
||||
}
|
||||
if (udpLogInit)
|
||||
{
|
||||
WHBLogUdpDeinit ();
|
||||
udpLogInit = false;
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
67
source/wiiu/logger.h
Normal file
67
source/wiiu/logger.h
Normal file
@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <coreinit/debug.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LOG_APP_TYPE "P"
|
||||
#define LOG_APP_NAME "homebrew_on_menu"
|
||||
|
||||
#define __FILENAME_X__ (strrchr (__FILE__, '\\') ? strrchr (__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr (__FILE__, '/') ? strrchr (__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
|
||||
#define LOG(LOG_FUNC, FMT, ARGS...) LOG_EX (LOG_FUNC, "", "", FMT, ##ARGS)
|
||||
|
||||
#define LOG_EX(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \
|
||||
do \
|
||||
{ \
|
||||
LOG_FUNC ("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, \
|
||||
LOG_APP_TYPE, \
|
||||
LOG_APP_NAME, \
|
||||
__FILENAME__, \
|
||||
__FUNCTION__, \
|
||||
__LINE__, \
|
||||
##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) LOG (WHBLogPrintf, FMT, ##ARGS)
|
||||
#else
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
#endif
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) LOG (WHBLogPrintf, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG (WHBLogWritef, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX (WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX (WHBLogPrintf, "##WARN ## ", "", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX (WHBLogPrintf, "##INFO ## ", "", FMT, ##ARGS)
|
||||
|
||||
#else
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX (OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX (OSReport, "##WARN ## ", "\n", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX (OSReport, "##INFO ## ", "\n", FMT, ##ARGS)
|
||||
|
||||
#endif
|
||||
|
||||
void initLogging ();
|
||||
|
||||
void deinitLogging ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -24,6 +24,7 @@
|
||||
#include "IOAbstraction.h"
|
||||
#include "ftpServer.h"
|
||||
#include "log.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <mocha/mocha.h>
|
||||
#include <nn/ac.h>
|
||||
@ -86,7 +87,8 @@ MochaUtilsStatus MountWrapper (const char *mount, const char *dev, const char *m
|
||||
}
|
||||
else
|
||||
{
|
||||
error ("Failed to mount %s: %s [%d]", mount, Mocha_GetStatusStr (res), res);
|
||||
DEBUG_FUNCTION_LINE_ERR (
|
||||
"Failed to mount %s: %s [%d]", mount, Mocha_GetStatusStr (res), res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -169,7 +171,8 @@ void start_server ()
|
||||
}
|
||||
else
|
||||
{
|
||||
OSReport ("Failed to init libmocha: %s [%d]\n", Mocha_GetStatusStr (res), res);
|
||||
DEBUG_FUNCTION_LINE_ERR (
|
||||
"Failed to init libmocha: %s [%d]\n", Mocha_GetStatusStr (res), res);
|
||||
}
|
||||
|
||||
server = FtpServer::create ();
|
||||
@ -209,7 +212,7 @@ static void gFTPServerRunningChanged (ConfigItemBoolean *item, bool newValue)
|
||||
auto res = WUPSStorageAPI::Store (FTPIIU_ENABLED_STRING, sFTPServerEnabled);
|
||||
if (res != WUPS_STORAGE_ERROR_SUCCESS)
|
||||
{
|
||||
OSReport ("Failed to store gFTPServerEnabled: %s (%d)\n",
|
||||
DEBUG_FUNCTION_LINE_ERR ("Failed to store gFTPServerEnabled: %s (%d)\n",
|
||||
WUPSStorageAPI::GetStatusStr (res).data (),
|
||||
res);
|
||||
}
|
||||
@ -232,7 +235,7 @@ static void gSystemFilesAllowedChanged (ConfigItemBoolean *item, bool newValue)
|
||||
auto res = WUPSStorageAPI::Store (SYSTEM_FILES_ALLOWED_STRING, sSystemFilesAllowed);
|
||||
if (res != WUPS_STORAGE_ERROR_SUCCESS)
|
||||
{
|
||||
OSReport ("Failed to store gSystemFilesAllowed: %s (%d)\n",
|
||||
DEBUG_FUNCTION_LINE_ERR ("Failed to store gSystemFilesAllowed: %s (%d)\n",
|
||||
WUPSStorageAPI::GetStatusStr (res).data (),
|
||||
res);
|
||||
}
|
||||
@ -300,6 +303,7 @@ INITIALIZE_PLUGIN ()
|
||||
if (WUPSConfigAPI_Init (configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) !=
|
||||
WUPSCONFIG_API_RESULT_SUCCESS)
|
||||
{
|
||||
DEBUG_FUNCTION_LINE_ERR ("Failed to init config api");
|
||||
OSFatal ("ftpiiu plugin: Failed to init config api");
|
||||
}
|
||||
|
||||
@ -308,7 +312,7 @@ INITIALIZE_PLUGIN ()
|
||||
FTPIIU_ENABLED_STRING, sFTPServerEnabled, DEFAULT_FTPIIU_ENABLED_VALUE)) !=
|
||||
WUPS_STORAGE_ERROR_SUCCESS)
|
||||
{
|
||||
OSReport ("ftpiiu plugin: Failed to get or create item \"%s\": %s (%d)\n",
|
||||
DEBUG_FUNCTION_LINE_ERR ("Failed to get or create item \"%s\": %s (%d)\n",
|
||||
FTPIIU_ENABLED_STRING,
|
||||
WUPSStorageAPI_GetStatusStr (err),
|
||||
err);
|
||||
@ -317,7 +321,7 @@ INITIALIZE_PLUGIN ()
|
||||
sSystemFilesAllowed,
|
||||
DEFAULT_SYSTEM_FILES_ALLOWED_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS)
|
||||
{
|
||||
OSReport ("ftpiiu plugin: Failed to get or create item \"%s\": %s (%d)\n",
|
||||
DEBUG_FUNCTION_LINE_ERR ("Failed to get or create item \"%s\": %s (%d)\n",
|
||||
SYSTEM_FILES_ALLOWED_STRING,
|
||||
WUPSStorageAPI_GetStatusStr (err),
|
||||
err);
|
||||
@ -325,9 +329,8 @@ INITIALIZE_PLUGIN ()
|
||||
|
||||
if ((err = WUPSStorageAPI::SaveStorage ()) != WUPS_STORAGE_ERROR_SUCCESS)
|
||||
{
|
||||
OSReport ("ftpiiu plugin: Failed to save storage: %s (%d)\n",
|
||||
WUPSStorageAPI_GetStatusStr (err),
|
||||
err);
|
||||
DEBUG_FUNCTION_LINE_ERR (
|
||||
"Failed to save storage: %s (%d)\n", WUPSStorageAPI_GetStatusStr (err), err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,6 +346,7 @@ void wiiu_init ()
|
||||
|
||||
ON_APPLICATION_START ()
|
||||
{
|
||||
initLogging ();
|
||||
nn::ac::Initialize ();
|
||||
nn::ac::ConnectAsync ();
|
||||
|
||||
@ -352,6 +356,7 @@ ON_APPLICATION_START ()
|
||||
ON_APPLICATION_ENDS ()
|
||||
{
|
||||
stop_server ();
|
||||
deinitLogging ();
|
||||
}
|
||||
|
||||
bool platform::init ()
|
||||
|
Loading…
Reference in New Issue
Block a user