DebugInOut Plugin
Recommended usage scenarios
- Development stage
Introduction
DebugInOut is a console output plugin. Its main focuses are:
- Quickly navigate to the business code handling the request (executed action)
- Current requesting user (player)
- The player's current connection type (webSocket, TCP, UDP)
- Thread executing the action
- Action execution time
- Route, class, method information, etc.
- Request parameters received by the action
- Data returned by the action to the player (response result)
When an action handles a request, the plugin prints the above information to the console. This means even new team members can quickly identify which action corresponds to each request, and quickly understand the overall project business flow.
Print Preview
When accessing an action business method, the console logs are printed as follows.
- CN
- EN
┏━━ Debug.(HallAction.java:18) ━━ [UserMessage loginVerify(String jwt)] ━━ [31-1] ━━ [tag:HallLogicServer, serverId:5656645] ━━━━
┣ userId: 1378604058
┣ 参数: Michael Jackson
┣ 响应: UserMessage(id=1378604058, nickname=Jack)
┣ 耗时: 1 ms
┗━━ [ionetVersion] ━━ [线程:User-8-1] ━━ [连接方式:WebSocket] ━━ [traceId:1761556037925] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┏━━ Debug.(HallAction.java:18) ━━ [UserMessage loginVerify(String jwt)] ━━ [31-1] ━━ [tag:HallLogicServer, serverId:5656645] ━━━━
┣ userId: 1378604058
┣ RequestParam: Michael Jackson
┣ ResponseData: UserMessage(id=1378604058, nickname=Jack)
┣ ExecutionTime: 1 ms
┗━━ [ionetVersion] ━━ [Thread:User-8-1] ━━ [ConnectionWay:WebSocket] ━━ [traceId:1761556037925] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Console output explanation
- code 1:
[Debug.(HallAction.java:18)]: the executed business class isHallAction, and18is the line number of the business method. ClickHallAction.java:18in the console to jump directly to the corresponding source code (quick code navigation). This is a core DX feature.[UserMessage loginVerify(String jwt)]: the executed method, including method parameters and return type.[31-1]: the route of this request.[tag:HallLogicServer]: logic service information that executed this request.
- code 2: current requester
userId. - code 3: request parameter passed by requester.
- code 4: response value that the framework pushes back to requester.
- code 5: total execution time of the business method, useful for optimization.
- code 6:
[ionetVersion]: current framework version.[Thread:User-8-1]: thread used to execute the action.[ConnectionWay:WebSocket]: connection type used by the user's external service.[traceId]: full-chain tracing id (very useful in distributed scenarios).
With this information, developers can locate issues quickly. Without this kind of observable information, development wastes significant time on frontend-backend communication. Typical issues include:
- Is it a request-parameter issue? (request side says parameter was sent)
- Is it a response issue? (backend says response was returned)
- Is it an execution-time issue? (request side says no response; backend says response was sent earlier)
Code navigation lets developers jump quickly to corresponding business class code. In collaborative projects, it helps quickly understand which methods were executed in a business flow, enabling fast reading and modifications.
How to Use
BarSkeletonBuilder builder = ...;
builder.addInOut(new DebugInOut());
Minimum print trigger time
The plugin supports a minimum trigger time for printing. The default is 0, which prints all requests.
You can set a threshold, for example 50 ms, and only requests exceeding this threshold will be printed.
BarSkeletonBuilder builder = ...;
builder.addInOut(new DebugInOut(50));
How to Ignore Printing
Sometimes we need to skip debug output for specific actions.
You can customize print behavior through DebugInOut.setPrintConsumer.
Hardcoding Way
code 9: do not print debug logs when route is
1-3.
public class MyLogicServer implements LogicServer {
@Override
public void settingBarSkeletonBuilder(BarSkeletonBuilder builder) {
var debugInOut = new DebugInOut();
builder.addInOut(debugInOut);
debugInOut.setPrintConsumer((message, flowContext) -> {
CmdInfo cmdInfo = flowContext.getCmdInfo();
if (cmdInfo.getCmd() == 1 && cmdInfo.getSubCmd() == 3) {
return;
}
System.out.println(message);
});
}
}
By Custom Annotation
- code 9: do not print
DebugInOutlogs. - code 21: custom annotation.
public class MyLogicServer implements LogicServer {
@Override
public void settingBarSkeletonBuilder(BarSkeletonBuilder builder) {
var debugInOut = new DebugInOut();
builder.addInOut(debugInOut);
debugInOut.setPrintConsumer((message, flowContext) -> {
ActionCommand actionCommand = flowContext.getActionCommand();
if (actionCommand.containAnnotation(IgnoreDebugInout.class)) {
return;
}
System.out.println(message);
});
}
}
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface IgnoreDebugInout {
}
Usage
@ActionController(1)
public class DemoAction {
@ActionMethod(3)
@IgnoreDebugInout
public String hello() {
return "hello";
}
}