Ts3 Php Framework Get Log ALL

With php framework I am pulling 100 logs with $ ts3 Virtual Server-> logView (100) function but $ ts3_VirtualServer-> logView (101) or $ ts3_VirtualServer-> logView (99999)
I get an error when I do.
How can I get all my log records?

Error 1541: invalid parameter size

not working :confused:

I did not open a forum on the same topic twice. The first is how to pull logs and the second is how to pull all logs. Your management is useless man


image

First of all, thank you for your time and reply. I’ll create an array and increase it to +100, but I don’t know how far

Watch your tone and learn some PHP basics…

As I explained in the other thread, the value for begin_pos must be the last_pos value from the previous result… it’s the cursor position inside of the log file. Check the first item in the array returned by the function.

Also, as stated in the documentation, the max number of lines to retrieve in a single command is 100.

4 Likes

First of all, my style is poorly understood for you, sorry.

$logs = $ts3_VirtualServer->logView(100,200,1);

echo "<pre>";
print_r($logs);
echo "</pre>";

normally the above code should show lines 201 - 300 but it doesn’t work.

Unfortunately, this is NOT how it works and the TeamSpeak Server documentation is wrong in this case. As I stated before, the begin_pos parameter of the logview command is NOT used to specify a number of lines to skip… instead, it specifies the position of the read cursor in the log file. You can see this in the output you posted as the date in the beginning of the second element in your output is incomplete.

Don’t ask me why… but that’s how it’s been implemented in the TeamSpeak Server.

So in fact, the function call you made does this:

Hey dude, give me 100 lines from the log starting after 200 bytes (characters)… pretty please.

To get the full log, what you actually need to do is this:

$log = array();
$pos = 0;

try
{
  do
  {
    // grab 100 lines starting at $pos bytes
    $lines = $ts3_virtualServer->logView(100, $pos);

    // remember cursor position of last line ending we got
    $pos = $lines[0]["last_pos"];

    // parse and save lines
    foreach($lines as $line) {
      $log[] = TeamSpeak3_Helper_Convert::logEntry($line["l"]);
    }
  }
  // do the above until no more content is available
  while($pos && $pos <= $lines[0]["file_size"]);
}
catch(TeamSpeak3_Exception $e)
{
  // print error message in case something goes wrong
  die("ERROR" . $e->getCode() . ": " . $e->getMessage());
}

// dump what we got
TeamSpeak3::dump($log);

However, I would not recommend to always grab the full log as it can get very large so what you should to is implement some kind of pagination to allow the user to navigate to newer/older log entries instead. Remember… you’re working on a file… not a database.

4 Likes

That was the answer I was looking for. Thank you <3