AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Logs in the Perl version
 
 

Is there a ‘best’ way to implement logs in the online Perl version?

I’m new to Perl. I can see a way creating text files, etc, but these need to be writable by multiple users if it goes fully online.

I’m wondering if the interpretor already has some facility to do this.

 

 
  [ # 1 ]

The interpreter doesn’t have built-in logging features, and it probably won’t (I don’t believe libraries should be “bloated” by having built-in support for a bunch of different database engines, etc.).

If you’re concerned about multi-user access, something like a MySQL database would be a good way to handle logs. Or to go with flat files, have one log for each user who chats with the bot (and therefore, only one bot process is likely to write to the file at the same time). wink A database is the most sure way to go, though. Maybe a schema like this:

CREATE TABLE chat_log (
  
id serial not null,
  
timestamp datetime default now(),
  
name varchar(32not null,
  
message text not null,
  
reply text not null,
); 

And Perl code like,

my $reply $rs->reply($user$message);
$dbh->prepare("INSERT INTO chat_log SET name=?, message=?, reply=?");
$dbh->execute($user$message$reply); 
 

 
  [ # 2 ]

Yes, that looks like the best approach. I had previously setup the text file per user for a different system, and thought then mysql was a better approach.

Agree 100% with you about not bloating. And I think you’ve done a really good job of deciding what should / shouldn’t be done by the interpreter (and the objects within the script idea is great as all the power is there to be used and no bloating).

Funnily enough, I spent about 1 hour yesterday searching for how to connect to mysql from Perl, and then getting that in a module. Got it to work, happily, then came here and saw you had already posted the code to do it. Still, was a good Perl learning experience.

 

 
  login or register to react