One of the methods of log processing in the game server

Source: Internet
Author: User
Tags system log

In the game development process, we need to record some logs in order to understand the game in the future, and according to the log to find and deal with the unexpected situation in the game.
One, the game log can be divided into the following types:
1) System Log
2) User operation log
3) Exception Log, which is the error log
System log
The system log generally describes the state of the server's daily operation. such as the success of the launch, the daily statistics on the amount of memory, CPU usage and other information. Used to search the health status of the server running. This is very important for technical analysis. Without this information, one but the server down, we have two eyes a wipe black, do not know where to start. This part of the log generally produces small files, not too much content, can be recorded in text form, in case of viewing. If you need to store it in a database or use a tool to view it, you need to define the format of the log to facilitate parsing.
User log
The core of the game server is the user's log. The user log can be divided into several categories: log logs, consumer journals, income journals, behavior logs, and the Journal of Duty.
1, login log
The main record of the player login time, IP and other information. Login logs can be used to determine the status of the client. Identify unusual, large-scale access using software. For example, frequent landings are broken. This can cause additional stress to the server. So that the normal players are affected, and sometimes serious, can not be properly logged in. Based on this information, the administrator can address the IP of this client.
2, Consumer Journal
The main record of the players in the game in the various currencies consumption situation. Based on this information, it is possible to analyze the flow of most of the players ' funds, which is very helpful to the marketing of the operation. You can also see if there are any bugs in the server system that are flashing money, based on this information. It is obviously not normal for a person to be able to purchase an item indefinitely. Based on these logs, you can quickly locate which feature is causing the situation to occur.
3, Income Journal
The main record of the player in the game's currency source situation. is also the performance of the entire game system output. It is easy to make a comprehensive understanding of the overall game output. It also helps to find bugs in the system, because it's not normal for a person's money to suddenly be much higher than other players. Based on these logs, you can navigate to which feature is causing the growth of this exception.
4 Behavior Log
The main record of the player's actions, such as the number of cards, the number of challenges, the number of purchases and other information. Analyze the behavior of the player during the growth of the game. Based on these logs, you can modify some of the game's small features to increase the user experience of goodwill.
5 Charge Duty Log
Mainly record the player's recharge information. This is very important, if a player recharge, money buckle, but the diamond has not been sent to others, is to give others a statement. The log can directly reflect which players are local tyrants, the source of the game's income clearly.
Exception Log
The main record is the exception that occurs in the game server program. Some bugs are hard to test in a test environment. Log the exception in the program, you can locate the bug in the program location, clear the cause of the bug. Provides the necessary support for the improvement of the game server.
Two
How the game logs are stored
Because the log storage is an IO-intensive operation, if the game logic is not handled properly, it will cause the game logic processing slow, the player's experience has a bad impact. The most commonly used log storage tool is log4j, the main is to store the log into a text file, about the use of log4j, we in another article in detail. Today we talk about the operation of storing logs. Before the log storage, be sure to define the format of the log, easy to parse the storage. such as log logs, need to record information by: User Id,ip, login time, etc., you can write these fields in an object, and then converted to a JSON string.
In general, logs are not associated with real-time gameplay. We can do a separate process development for log inbound operations. Let it run on another physical machine separate from the game logic server. This reduces the use of the game's logical server resources and reduces the stress on the logical server. The way it is implemented is simple. Initialize a queue in the game logic server:

</pre><pre name= "code"  class= "Java" >import  Java.util.concurrent.blockingqueue;import java.util.concurrent.linkedblockingqueue;public class  LogManager {//  Log Cache Queue Private final static blockingqueue<string> log_ Queue = new linkedblockingqueue<string> ();p ublic static void put (String  log)  {try {log_queue.put (log);}  catch  (interruptedexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();}} Public static string get ()  {try {return log_queue.take ();}  catch  (interruptedexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();} Return null;}} 




When the server starts, a thread is started and the log is removed from the log cache queue and sent to the log server as a socket. The log server receives the log sent over. Because the log server to write to the database, in order to check the large-scale write, resulting in the database connection resource consumption, the log server also set up a cache queue, the log is first placed in the cache queue. Additionally, several threads are connected to the database and the log data is fetched from the cache queue and written to the log database. In the log database, the log table is stored by day, that is, a table for a day, and is automatically completed by the program. Due to the large amount of data in the log, you can back up and delete outdated data in the database, or you can make data processing

One of the methods of log processing in the game server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.