[SOLVED]Debugging... traces?

Game development with Board Game Arena Studio
Post Reply
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

[SOLVED]Debugging... traces?

Post by Rudolf »

HELLO,
Well I've not used studio for a long time, and I don't remember how to log my messages in PHP.

I've tried theses:
self::trace("!TRACE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
self::debug("!DEBUG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
self::warn ("!WARN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
self::error("!ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

I don't know where is the output!!! I see nothing in the log window.
The only way I have a message , it's when i use
throw new feException ("MYMESSAGE");

or when I Use print_r("!PRINTR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
this way i see the message:
Erreur inattendue: Wrong formatted data from BGA gameserver 1 (method: createGame): !PRINTR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{"status":1,"data":true}

same thing with a variable:
print_r($sort);
Erreur inattendue: Wrong formatted data from BGA gameserver 1 (method: createGame): Array ( [0] => 1_1 [1] => 2_1 [2] => 3_1 [3] => 4_1 [4] => 5_1 [5] => 6_1 [6] => 7_1 [7] => 1_2 [8] => 2_2 [9] => 3_2 [10] => 4_2 [11] => 5_2 [12] => 6_2 [13] => 7_2 [14] => 1_4 [15] => 2_4 [16] => 3_4 [17] => 4_4 [18] => 5_4 [19] => 6_4 [20] => 7_4 ) {"status":1,"data":true}

... so i've got this solution, but seeing "Practical debugging" in Studio Info, it seems not to be the right way to do it?
Last edited by Rudolf on 03 August 2015, 12:42, edited 1 time in total.
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: Debugging... traces?

Post by pikiou »

I don't know the answer but I use my own logging system and here is the code.

In dbmodel.sql:

Code: Select all

CREATE TABLE IF NOT EXISTS `logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `line` mediumtext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
In yourgame.game.inc.php:

Code: Select all

In the constructor:
$this->inStudio = preg_match('/(studio|far)\\.boardgamearena\\.com/', $_SERVER['SERVER_NAME']);

Anywhere:
function log() {
   if ($this->inStudio) {
      $args = func_get_args();
      $line = Array();
      foreach ($args as $arg) {
         $line[] = is_string($arg) ? $arg : var_export($arg, true);
      }
      self::DbQuery("INSERT INTO logs (line) VALUE ('".mysql_escape_string(implode("\n\n", $line))."')");
   }
}

In getAllDatas:
if ($this->inStudio) {
if ($this->inStudio) {
   if (isset($_GET['show'])) {
      $sql = "SELECT id, line
              FROM logs";
      echo '<pre>' . implode("\r\n<hr>", self::getCollectionFromDB($sql, true)) . '</pre>';
   }
   if (isset($_GET['del'])) {
      $sql = "DELETE FROM logs";
      self::DbQuery($sql);
      die("Logs cleared!<br/>\r\n");
   }
   if (isset($_GET['show'])) {
      die();
   }
}
Now you can use $this->log() with any number of parameters, they'll be var_exported to the same line in the log table.
If you want to show the log table without having to log into the DB, you add "&show" to the table page url, and if you want to reset the log table, add "&del" (it's cleared after it's shown).
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Debugging... traces?

Post by Rudolf »

thanks pikiou :)
maybe you could change the documentation of studio §pratical debugging with this?
rudolf
Post Reply

Return to “Developers”