-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐳 #271 游戏对外服 - 增加 log 相关的 netty Handler
- Loading branch information
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...l-netty/src/main/java/com/iohao/game/external/core/netty/handler/SimpleLoggerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* ioGame | ||
* Copyright (C) 2021 - present 渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved. | ||
* # iohao.com . 渔民小镇 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.iohao.game.external.core.netty.handler; | ||
|
||
import io.netty.channel.ChannelHandler; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* 简单日志打印,通常是不活跃的连接、触发异常的连接 | ||
* | ||
* @author 渔民小镇 | ||
* @date 2024-05-01 | ||
*/ | ||
@Slf4j | ||
@ChannelHandler.Sharable | ||
public final class SimpleLoggerHandler extends ChannelInboundHandlerAdapter { | ||
|
||
@Override | ||
public void channelInactive(ChannelHandlerContext ctx) throws Exception { | ||
log.info("channelInactive channel.remoteAddress() : {}", ctx.channel().remoteAddress()); | ||
super.channelInactive(ctx); | ||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { | ||
log.error(cause.getMessage(), cause); | ||
super.exceptionCaught(ctx, cause); | ||
} | ||
|
||
private SimpleLoggerHandler() { | ||
} | ||
|
||
public static SimpleLoggerHandler me() { | ||
return Holder.ME; | ||
} | ||
|
||
/** 通过 JVM 的类加载机制, 保证只加载一次 (singleton) */ | ||
private static class Holder { | ||
static final SimpleLoggerHandler ME = new SimpleLoggerHandler(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters