KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to do Dashboard logging? #2763

Open GHSix opened this topic on on Jul 25 - 3 comments

GHSix commented on Jul 25

Following the dashboard logging docs. I have created this files:

AppLog.php

<?php
namespace mydash\AppLog;

class AppLog extends \koolreport\dashboard\Log
{
    protected function settings()
    {
        return [
            "mychannel"=>[                                      
                'chromePHP'=>[
                    'chromePHPHandler'=>new ChromePHPHandler(Logger::DEBUG, true, 8),
                    'level'=>'debug'
                ],
                "rotatingFile"=>[
                    "filename"=>"/tmp/dash.log",
                    "maxFiles"=>2,
                    "level"=>"debug",
                    "buddle"=>true,
                    "filePermission"=>null,
                    "useLocking"=>false
                ]
            ]
        ];
    }
}

UserChart.php

<?php

use \koolreport\dashboard\widgets\google\DonutChart;
use \koolreport\dashboard\fields\Text;
use \mydash\AppLog;

class UsersChart extends DonutChart
{
    protected function onCreated()
    {
        $this->title('Gráfico de usuários');
        AppLog::debug('Usuarios'); // <-- This line makes it stop working
    }

    protected function dataSource()
    {
        /*return AutoMaker::table('portal_users')
        ->select('IF(active = 0, "Inativo", "Ativo")')->label('label')
        ->groupBy('active')
        ->count('active')->alias('total');*/

        return AutoMaker::rawSQL('
            SELECT COUNT(*) total, IF(active = 0, "Inativo", "Ativo") label 
            FROM portal_users
            GROUP BY active
        ');
    }
    
    protected function fields()
    {
        return [
            Text::create('label'),
            Text::create('total')
        ];
    }
}

I'm new to Koolreport and Dashboard and I was intending to debug my rawSQL result to try to understand why the donut chart is all gray, but I can't get paste the logging test at onCreated, since that log line makes the dashboard respond this:

The application encountered an unexpected condition that prevented it from fulfilling your request

I tryend with and without requiring AppLog.php at index.php along side App.log, not sure if necessary, but none worked. Could you please help, pointing me to the right direction?

Thanks.

GHSix commented on Jul 27

I see that the response time in Forums is, almost always, in the first 24 hours, This questions is 48+ hours old already. Or I have a very difficult question, or logging is just broken. Hoping for the first one.

I have managed to get my chart working by just changing Text::create('total') for Number::create('total'). This lead me to believe it's kinf of lacking in the docs an explanation that the field type must match the query column type and no implicit conversion will be made as one would expect in the PHP world.

As for debugging I'm using plain print_r for now, till someone can better explain monolog usage inside dashboard.

GHSix commented on Aug 1

Got it. Now I'm understanding better the namespace and use keywords and how they work in Dashboard.

In my own example, just removing

namespace mydash\AppLog;

and

use \mydash\AppLog;

makes it works, since AppLog.php is in the same folder.

KoolReport commented on Aug 2

We are sorry for missing your topic, the namespace should represent the folder that contains the php files. For example, you have a structure like this:

|-App.php
|-subfolder
  |--MyClass.php

If your App.php has namespace myproject (its full class name is \myproject\App)

namespace myproject;

class App extends \koolreport\dashboard\Application
{
}

then the MyClass should have namespace myproject\subfolder like this:

namespace myproject\subfolder;

class MyClass
{

} 

The full classname of MyClass is \myproject\subfolder\MyClass.

In anywhere, you can use the full classname of a class then Dashboard Framework will base on the full classname to locate the php file to include for you (so that you don't have to use the include or require).

Hope my explanation is good.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Dashboard