com.tenio.common.logger.SystemLogger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tenio-common Show documentation
Show all versions of tenio-common Show documentation
TenIO is a java NIO (Non-blocking I/O) based server specifically designed for multiplayer games.
It supports UDP and TCP transports which are handled by Netty for high-speed network transmission.
This is the common module for multipurpose use of the framework.
/*
The MIT License
Copyright (c) 2016-2022 kong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package com.tenio.common.logger;
/**
* The recording logs of a developer is important for every system. This class
* uses Log4j for robust and
* fast logging. It uses a pool mechanism to increase performance. Every class
* should be derived from this one so that you can have more chances to
* investigate bugs in the production environment via daily log files.
*/
public abstract class SystemLogger extends AbstractLogger {
/**
* Only use for debugging EVENTS in the server system. Be careful when using it
* yourself. You are warned!
*
* @param type the event's type
* @param msg the extra information for "type"
*/
public void debug(String type, Object... msg) {
if (!logger.isDebugEnabled()) {
return;
}
var builder = stringPool.get();
builder.append("{").append(type).append("} ");
for (int i = 0; i < msg.length - 1; i++) {
builder.append(msg[i]).append(", ");
}
if (msg.length > 0) {
builder.append(msg[msg.length - 1]);
}
logger.debug(builder.toString());
stringPool.repay(builder);
}
/**
* Only use for debugging EVENTS in the server system. Be careful when using it
* yourself. You are warned!
*
* @param type the event's type
* @param msg the extra information for "type"
*/
public void trace(String type, Object... msg) {
if (!logger.isTraceEnabled()) {
return;
}
var builder = stringPool.get();
builder.append("<").append(type).append("> ");
for (int i = 0; i < msg.length - 1; i++) {
builder.append(msg[i]).append(", ");
}
if (msg.length > 0) {
builder.append(msg[msg.length - 1]);
}
logger.trace(builder.toString());
stringPool.repay(builder);
}
/**
* Only use for debugging PACKAGE in the server system. Be careful when using it
* yourself. You are warned!
*
* @param where where you put this log
* @param subWhere the extra information for "where" you put this log
* @param tag the tag type
* @param msg the message content
*/
public void trace(String where, Object subWhere, String tag, String msg) {
if (!logger.isTraceEnabled()) {
return;
}
var builder = stringPool.get();
builder.append("<").append(where).append(" ").append(subWhere).append(">").append("[")
.append(tag).append("] ")
.append(msg);
logger.trace(builder.toString());
stringPool.repay(builder);
}
}