Skip to content

Commit

Permalink
Add context to log tracer callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Oct 26, 2024
1 parent 8db3f3e commit 1b0e4e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/twbl/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "tracer.h"

void twbl_default_log_tracer(const char *pLine, int Offset)
void twbl_default_log_tracer(const char *pLine, int Offset, void *pContext)
{
// if you do not want to see a full path in the log
// you can implement your own tracer
Expand Down
2 changes: 1 addition & 1 deletion src/twbl/tracer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef TWBL_SRC_TWBL_TRACER_H
#define TWBL_SRC_TWBL_TRACER_H

void twbl_default_log_tracer(const char *pLine, int Offset);
void twbl_default_log_tracer(const char *pLine, int Offset, void *pContext = nullptr);

#endif
10 changes: 5 additions & 5 deletions src/twbl/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#endif

typedef void (*FCallbackDie)(CCharacter *pChr);
typedef void (*FStrTraceCallback)(const char *pStr, int Offset);
typedef void (*FStrTraceCallback)(const char *pStr, int Offset, void *pContext);

class CServerBotStateIn
{
Expand Down Expand Up @@ -177,13 +177,13 @@ class CServerBotStateOut
#endif
}

void TraceDir(FStrTraceCallback pCallback = twbl_default_log_tracer, int MaxHist = TWBL_MAX_LOG_LEN) const
void TraceDir(FStrTraceCallback pCallback = twbl_default_log_tracer, void *pContext = nullptr, int MaxHist = TWBL_MAX_LOG_LEN) const
{
#ifdef TWBL_DEBUG
char aLine[512];
char aBuf[512];
str_format(aLine, sizeof(aLine), "Dir=%d", m_Direction);
pCallback(aLine, 0);
pCallback(aLine, 0, pContext);

for(int i = 0; i < TWBL_MAX_LOG_LEN; i++)
{
Expand All @@ -193,10 +193,10 @@ class CServerBotStateOut
break;

str_format(aBuf, sizeof(aBuf), " %s", aLine);
pCallback(aBuf, i + 1);
pCallback(aBuf, i + 1, pContext);
}
#else
pCallback("to use tracing compile with -DTWBL_DEBUG=ON", 0);
pCallback("to use tracing compile with -DTWBL_DEBUG=ON", 0, nullptr);
#endif
}

Expand Down

0 comments on commit 1b0e4e6

Please sign in to comment.