Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions projects/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ endif()
include_directories ($<BUILD_INTERFACE:${RLOTTIE_ROOT}/inc> ${RLOTTIE_ROOT}/src/vector/ ${RLOTTIE_ROOT}/vs2019/)
message("Lottie root directory: ${RLOTTIE_ROOT}")

set (RLOTTIE_PLUGIN_LIBRARY_SOURCES
../../src/LottiePlugin.cpp)
set (RLOTTIE_PLUGIN_LIBRARY_SOURCES
../../src/LottieLogger.cpp
../../src/LottiePlugin.cpp)

if (RLOTTIE_OSX OR RLOTTIE_IOS)
set_source_files_properties(${RLOTTIE_PLUGIN_LIBRARY_SOURCES} PROPERTIES LANGUAGE OBJCXX)
Expand Down
143 changes: 143 additions & 0 deletions src/LottieLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include "LottieLogger.h"

#include <atomic>
#include <cstdarg>
#include <cstdio>

#if !defined(__EMSCRIPTEN__)
#include "IUnityLog.h"

#if defined(__ANDROID__)
#include <android/log.h>
#define LOTTIE_ANDROID_LOG_TAG "LottiePlugin"
#endif

static std::atomic<LottieLogLevel> sGlobalLogLevel(LOTTIE_LOG_INFO);
static IUnityLog* sLog = nullptr;

void LottieLoggerSetUnityLog(IUnityLog* log)
{
sLog = log;
}

LottieLogLevel LottieGetGlobalLogLevel()
{
return sGlobalLogLevel.load();
}

void LottieSetGlobalLogLevel(LottieLogLevel level)
{
sGlobalLogLevel.store(level);
}

void LottieLogInfo(lottie_animation_wrapper* animation, const char* format, ...)
{
LottieLogLevel level = animation ? animation->logLevel : sGlobalLogLevel.load();
if (level >= LOTTIE_LOG_INFO)
{
char buffer[512];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_INFO, LOTTIE_ANDROID_LOG_TAG, "%s", buffer);
#endif
if (sLog)
{
UNITY_LOG(sLog, buffer);
}
}
}

void LottieLogWarning(lottie_animation_wrapper* animation, const char* format, ...)
{
LottieLogLevel level = animation ? animation->logLevel : sGlobalLogLevel.load();
if (level >= LOTTIE_LOG_WARNING)
{
char buffer[512];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_WARN, LOTTIE_ANDROID_LOG_TAG, "%s", buffer);
#endif
if (sLog)
{
UNITY_LOG_WARNING(sLog, buffer);
}
}
}

void LottieLogError(lottie_animation_wrapper* animation, const char* format, ...)
{
LottieLogLevel level = animation ? animation->logLevel : sGlobalLogLevel.load();
if (level >= LOTTIE_LOG_ERROR)
{
char buffer[512];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_ERROR, LOTTIE_ANDROID_LOG_TAG, "%s", buffer);
#endif
if (sLog)
{
UNITY_LOG_ERROR(sLog, buffer);
}
}
}

#else

static std::atomic<LottieLogLevel> sGlobalLogLevel(LOTTIE_LOG_INFO);

void LottieLoggerSetUnityLog(IUnityLog*) {}

LottieLogLevel LottieGetGlobalLogLevel()
{
return sGlobalLogLevel.load();
}

void LottieSetGlobalLogLevel(LottieLogLevel level)
{
sGlobalLogLevel.store(level);
}

// WebGL logging - output to browser console via printf
void LottieLogInfo(lottie_animation_wrapper*, const char* format, ...)
{
if (sGlobalLogLevel.load() < LOTTIE_LOG_INFO) return;
va_list args;
va_start(args, format);
printf("[Lottie INFO] ");
vprintf(format, args);
printf("\n");
va_end(args);
}

void LottieLogWarning(lottie_animation_wrapper*, const char* format, ...)
{
if (sGlobalLogLevel.load() < LOTTIE_LOG_WARNING) return;
va_list args;
va_start(args, format);
printf("[Lottie WARNING] ");
vprintf(format, args);
printf("\n");
va_end(args);
}

void LottieLogError(lottie_animation_wrapper*, const char* format, ...)
{
if (sGlobalLogLevel.load() < LOTTIE_LOG_ERROR) return;
va_list args;
va_start(args, format);
printf("[Lottie ERROR] ");
vprintf(format, args);
printf("\n");
va_end(args);
}

#endif
16 changes: 16 additions & 0 deletions src/LottieLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef LOTTIE_LOGGER_H
#define LOTTIE_LOGGER_H

#include "LottiePlugin.h"

struct IUnityLog;

void LottieLoggerSetUnityLog(IUnityLog* log);
LottieLogLevel LottieGetGlobalLogLevel();
void LottieSetGlobalLogLevel(LottieLogLevel level);

void LottieLogInfo(lottie_animation_wrapper* animation, const char* format, ...);
void LottieLogWarning(lottie_animation_wrapper* animation, const char* format, ...);
void LottieLogError(lottie_animation_wrapper* animation, const char* format, ...);

#endif // LOTTIE_LOGGER_H
119 changes: 7 additions & 112 deletions src/LottiePlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "LottiePlugin.h"
#include "LottieLogger.h"
#include "vdebug.h"

#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstring>
Expand All @@ -17,11 +17,6 @@
#include <utility>
#include <vector>

#if defined(__ANDROID__)
# include <android/log.h>
# define LOTTIE_ANDROID_LOG_TAG "LottiePlugin"
#endif

// --- Platform GPU headers FIRST ---
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -56,7 +51,6 @@ extern "C" {

static IUnityGraphics* sUnityGraphics = nullptr;
static IUnityProfiler* sProfiler = nullptr;
static IUnityLog* sLog = nullptr;
static const UnityProfilerMarkerDesc* sMkGetResult = nullptr;
static const UnityProfilerMarkerDesc* sMkPublish = nullptr;
static const UnityProfilerMarkerDesc* sMkUpload = nullptr;
Expand Down Expand Up @@ -84,69 +78,6 @@ static inline void ProfEnd(const UnityProfilerMarkerDesc* d)
sProfiler->EndSample(d);
}
}

// Global log level (default: Info – verbose logging)
static std::atomic<LottieLogLevel> sGlobalLogLevel(LOTTIE_LOG_INFO);

static inline void LottieLogInfo(lottie_animation_wrapper* animation, const char* format, ...)
{
LottieLogLevel level = animation ? animation->logLevel : sGlobalLogLevel.load();
if (level >= LOTTIE_LOG_INFO)
{
char buffer[512];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_INFO, LOTTIE_ANDROID_LOG_TAG, "%s", buffer);
#endif
if (sLog)
{
UNITY_LOG(sLog, buffer);
}
}
}

static inline void LottieLogWarning(lottie_animation_wrapper* animation, const char* format, ...)
{
LottieLogLevel level = animation ? animation->logLevel : sGlobalLogLevel.load();
if (level >= LOTTIE_LOG_WARNING)
{
char buffer[512];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_WARN, LOTTIE_ANDROID_LOG_TAG, "%s", buffer);
#endif
if (sLog)
{
UNITY_LOG_WARNING(sLog, buffer);
}
}
}

static inline void LottieLogError(lottie_animation_wrapper* animation, const char* format, ...)
{
LottieLogLevel level = animation ? animation->logLevel : sGlobalLogLevel.load();
if (level >= LOTTIE_LOG_ERROR)
{
char buffer[512];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
#if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_ERROR, LOTTIE_ANDROID_LOG_TAG, "%s", buffer);
#endif
if (sLog)
{
UNITY_LOG_ERROR(sLog, buffer);
}
}
}
#else
struct IUnityInterfaces;
struct UnityProfilerMarkerDesc;
Expand All @@ -157,42 +88,6 @@ static inline void ProfEnd(const UnityProfilerMarkerDesc*) {}
static const UnityProfilerMarkerDesc* sMkGetResult = nullptr;
static const UnityProfilerMarkerDesc* sMkPublish = nullptr;
static const UnityProfilerMarkerDesc* sMkUpload = nullptr;

// WebGL logging - output to browser console via printf
static std::atomic<LottieLogLevel> sGlobalLogLevel(LOTTIE_LOG_INFO);

static inline void LottieLogInfo(lottie_animation_wrapper*, const char* format, ...)
{
if (sGlobalLogLevel.load() < LOTTIE_LOG_INFO) return;
va_list args;
va_start(args, format);
printf("[Lottie INFO] ");
vprintf(format, args);
printf("\n");
va_end(args);
}

static inline void LottieLogWarning(lottie_animation_wrapper*, const char* format, ...)
{
if (sGlobalLogLevel.load() < LOTTIE_LOG_WARNING) return;
va_list args;
va_start(args, format);
printf("[Lottie WARNING] ");
vprintf(format, args);
printf("\n");
va_end(args);
}

static inline void LottieLogError(lottie_animation_wrapper*, const char* format, ...)
{
if (sGlobalLogLevel.load() < LOTTIE_LOG_ERROR) return;
va_list args;
va_start(args, format);
printf("[Lottie ERROR] ");
vprintf(format, args);
printf("\n");
va_end(args);
}
#endif

#if defined(__APPLE__)
Expand Down Expand Up @@ -1359,7 +1254,7 @@ namespace
animation_wrapper->width = width;
animation_wrapper->height = height;
animation_wrapper->animation = std::move(animation);
animation_wrapper->logLevel = sGlobalLogLevel.load();
animation_wrapper->logLevel = LottieGetGlobalLogLevel();
LottieLogInfo(animation_wrapper, "[Lottie] Created animation wrapper: width=%lld, height=%lld, fps=%.2f, frames=%lld, duration=%.2fs",
(long long)animation_wrapper->width, (long long)animation_wrapper->height,
animation_wrapper->frameRate, (long long)animation_wrapper->totalFrame,
Expand Down Expand Up @@ -1680,14 +1575,14 @@ extern "C"
else
{
// Set global log level if no specific animation wrapper
sGlobalLogLevel.store(log_level);
LottieSetGlobalLogLevel(log_level);
}
return 0;
}

EXPORT_API int32_t lottie_set_global_log_level(LottieLogLevel log_level)
{
sGlobalLogLevel.store(log_level);
LottieSetGlobalLogLevel(log_level);
LottieLogInfo(nullptr, "[Lottie] Global log level changed to %d", (int)log_level);
return 0;
}
Expand Down Expand Up @@ -1980,12 +1875,12 @@ extern "C"
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
#if !defined(__EMSCRIPTEN__)
// Early logging before sLog is set (uses printf on iOS)
// Early logging before Unity's logger is set (uses printf on iOS)
#if defined(__APPLE__)
printf("[Lottie] UnityPluginLoad called (unityInterfaces=%p)\n", (void*)unityInterfaces);
fflush(stdout);
#endif
sLog = unityInterfaces != nullptr ? unityInterfaces->Get<IUnityLog>() : nullptr;
LottieLoggerSetUnityLog(unityInterfaces != nullptr ? unityInterfaces->Get<IUnityLog>() : nullptr);
LottieLogInfo(nullptr, "[Lottie] Plugin loading...");
sProfiler = unityInterfaces != nullptr ? unityInterfaces->Get<IUnityProfiler>() : nullptr;
if (sProfiler != nullptr && sProfiler->IsAvailable())
Expand Down Expand Up @@ -2141,7 +2036,7 @@ extern "C"
sMetalV1 = nullptr;
# endif
LottieLogInfo(nullptr, "[Lottie] Plugin unloaded successfully");
sLog = nullptr;
LottieLoggerSetUnityLog(nullptr);
#endif
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.