31. Game operation part 3: Logging player activity

Logs left on the game server generally fall into the following two categories: 1) logs for program debugging and 2) user activity logs for customer support.

There are many more of the former and they are only needed when there is a server problem, even though they are saved in the DB. There are relatively few of the latter, but they must be persistently stored in the DB. iFun Engine supports both debugging and player activity logs.

This chapter will cover player activity logs. For more about debugging logs, see Programming part 1: Debugging logs.

31.1. Activity Logger Overview

Since gameplay that must be logged is different for each game, iFun Engine uses a logger function to record activity logs in the form of JSON files. Programmers can now use that logger to leave logs. Activity logs are managed separately from program logs using MongoDB or JSON.

Tip

If the game runs on iFun Deploy, activity log files are collected and saved in the DB.

31.2. Activity logger definition files

If we make a project called funapi_initiator my_project, a JSON file defining the logger is made with the name src/my_project_loggers.json.

Logs are defined with the following structure in this file.

{
  "LogType1": {
    "Argument1": "Type1"
  },

  "LogType2": {
    "Argument1": "Type1",
    "Argument2": "Type2"
  }
}

For example, you can set using the following method.

{
  "SessionOpened": {
    "session_id": "string",
    "when": "datetime2"
  },
  "SessionClosed": {
    "session_id": "string",
    "when": "datetime2"
  },
  "PlayerLoggedIn": {
    "session_id": "string",
    "account_id": "string",
    "when": "datetime2"
  },
  "PlayerDropItem": {
    "player_name": "string",
    "item_name": "string"
  }
}

31.2.1. Activity logger type parameters

The following can be used with the type value.

Type Description
bool True/false
double Real number form
integer Integer form
string Text string form
datetime date type (time_t form)
datetime2 data type (WallClock::Value form)

31.3. Automatically generated logger function

When defined and compiled as above, the following logger function is automatically generated.

namespace logger {

void SessionOpened(const string &session_id, const WallClock::Value &when);
void SessionClosed(const string &session_id, const WallClock::Value &when);
void PlayerLoggedIn(const string &session_id, const string &account_id, const WallClock::Value &when);
void PlayerDropItem(const string &player_name, const string &item_name);

}  // namespace logger

가령 플레이어가 아이템을 떨굴 때마다 이제 logger:PlayerItemDrop() 을 호출하면 됩니다.

class ActivityLog {

  public void SessionOpened(string arg_session_id, System.DateTime arg_when);
  public void SessionClosed(string arg_session_id, System.DateTime arg_when);
  public void PlayerLoggedIn(string arg_session_id, string arg_account_id, System.DateTime arg_when);
  public void PlayerLoggedIn(string arg_player_name, string arg_item_name);

}

가령 플레이어가 아이템을 떨굴 때마다 이제 ActivityLog.PlayerItemDrop() 을 호출하면 됩니다.

31.3.1. Parameter type and programming language type matching

Each activity logger type matches a programming language type, as follows.

Logger type C++ type C# type
bool const bool bool
double const double double
integer const int64_t long
string const string & string
datetime time_t System.DateTime
datetime2 const WallClock::Value & System.DateTime

31.4. Activity logger save location

Activity logs are saved in MANIFEST.json.

File, DB, and Syslog format are available.

The following is an example of MANIFEST.json.

"Logging": {
  "activity_log_output": "json://activity_log/test",
  "activity_log_rotation_interval": 60
}

In the example above, log location differs depending on activity_log_output value. The following are available.

31.4.1. Output as standard I/O

  • stdout: Log output as standard output.
  • stderr: Log output as standard error.

31.4.2. Redirect to another logger

  • glog: Combined with glog created by program log and output. (For more details, please see Programming part 1: Debugging logs.)
  • syslog://procname: Output as syslog’s INFO level. Here, procname is the program name. This feature only works in Linux.

31.4.3. Saving in files

  • file://path/to/filename: Under the directory path/to/date, a file is created in the form filename.time, and each field is delimited by a comma one line at a time.
  • json://path/to/file: Similar to files but each line delimited by a comma is created in JSON format rather than as a log.

Note

The file format is generated in a particular directory called log root, and the rules for this are as follows.

  • At the development stage, it is in the activity_log/ directory under the build directory.
  • At the live stage, it is in /var/log/funapi/{{ project_name }}/activity_log.

31.4.4. Saving in the DB

  • mongodb://user:passwd@host:port/database: Logs are created in a particular MongoDB database. User, password, and port are optional. For example, it may be in the same format as mongodb://localhost:27017/my_activity_log. Please refer to MongoDB CXX Driver’s ConnectionString for more on replica sets.

    MongoDB 에 로그를 남기기 위해서는 다음처럼 추가 패키지를 설치해주시기 바랍니다. MongoDB 서버를 설치하는 방법은 MongoDB 를 참고해주세요.

    • Ubuntu:

      sudo apt-get install libfunapi1-mongodblogger
      
    • CentOS:

      sudo yum install funapi1-mongodblogger
      

    또한, MANIFEST.jsonMongoDbBase 항목을 추가해야합니다.

    "Logging": {
      "activity_log_output": "mongodb://localhost:27017/activity_log",
    },
    "MongoDbBase": {
       "mongodb_logger_enable_ssl": false
    }
    

    Note

    SSL/TLS 연결이 필요한 경우 mongdb_logger_enable_ssl 옵션을 true 로 변경해야 합니다.

31.5. Activity logger parameters

Add the following to a MANIFEST.json Logging session.

  • activity_log_output: Activity log storage path. As explained above, the following values are available.

    • stdout
    • stderr
    • glog
    • syslog://name
    • file://path/to/file
    • json://path/to/file
    • mongodb://user:passwd@host:port

    Note

    Syslog only works in Linux.

  • activity_log_rotation_interval: Cycle in seconds to rotate activity logs. (type=int32, default=60)

  • activity_log_write_schema: Whether or not schema data is output to activity logs (type=bool, default=true)