• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Custom Log Helper

#1
Question 
Hello I am trying to implement a Database Log Handler to store logs directly to the database, but I am having trouble adding the new logger. My class is not being found when I log a new message. I continuously get this error:

   
 Any help would be appreciated! I have added the new logger to the Config\Logger.php file like this: 


PHP Code:
'App\Libraries\DatabaseLogHandler'  => [
                
/*
                 * The log levels that this handler will handle.
                 */
                
'handles' => ['critical''alert''emergency''debug',
                            
  'error''info''notice''warning'],
            ] 



And I have the DatabaseLogHandler.php file in my Libraries folder (should I put this in a different folder?):
PHP Code:
<?php

namespace App\Libraries;

use 
App\Entities\Log;
use 
App\Models\LogModel;
use 
CodeIgniter\Log\Handlers\BaseHandler;
use 
CodeIgniter\Log\Handlers\HandlerInterface;

class 
DatabaseLogHandler extends BaseHandler implements HandlerInterface
{
    protected $logModel;
    protected $log;

    public function __construct(array $config = [])
    {
        parent::__construct($config);

        $this->logModel = new LogModel();
        $this->log = new Log();

    }

    public function handle($level$message): bool
    

        $this->log->log_message $message;
        $this->log->level $level;
        $this->log->status "Open";
        $this->log->log_type "Website";
        $this->log->setCreatedAt(date('Y-m-d H:i:s'));
        $this->logModel->insert($this->log);
        return true;
    }

Reply

#2
How are you calling it? No it's in the right place so something else is wrong.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
The issue seems to be resolved now. I was logging the message incorrectly.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.