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?
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.
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.