Welcome Guest, Not a member yet? Register   Sign In
Using Custom Log Helper
#1
Question 
(This post was last modified: 08-16-2020, 12:51 PM by jjohn379. Edit Reason: Inserting attachment into post. )

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


Messages In This Thread
Using Custom Log Helper - by jjohn379 - 08-16-2020, 12:06 PM
RE: Using Custom Log Helper - by InsiteFX - 08-17-2020, 03:27 AM
RE: Using Custom Log Helper - by jjohn379 - 08-17-2020, 10:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB