Console log

Swoft provides easy console log usage for easy printing of debug information during development.

Configuration

Start the application inside ( app\Application.php ) to override the parent class method to override the configuration console log parameters.

 namespace App;

use Swoft\SwoftApplication;

/**
 * Class Application
 *
 * @since 2.0
 */
class Application extends SwoftApplication
{
    public function getCLoggerConfig(): array
    {
        return [
            'name'    => 'swoft',
            'enable'  => true,
            'output'  => true,
            'levels'  => 'info,error',
            'logFile' => ''
        ];
    }
} 

Option description

  • name name
  • Whether enable is enabled
  • Whether output is printed to the console
  • levels level input log, all output is empty, the specific configuration log level value, can be cited Logger::NOTICE/...
  • logFile console log is printed to the console by default. You can also configure the path and write to the specified file.

Swoft 2.0.3 levels modified into strings for developers to override the frame default configuration

use

The console log can be manipulated directly using the static methods in the CLog class provided by the framework.

  • Each log level method can pass parameters, the bottom layer is a sprintf() function package
  • Special: debug log level, you need to enable SWOFT_DEBUG to display
  • The frame has different levels of different colors built in
 // debug
CLog::debug('debug');

// info 
CLog::info('info');

// warning
CLog::warning('warning');

// error
CLog::error('error');

// 2019/05/12-07:02:57 [DEBUG] Swoft\Processor\ConsoleProcessor:handle(33) debug
// 2019/05/12-07:02:57 [INFO] Swoft\Processor\ConsoleProcessor:handle(33) info
// 2019/05/12-07:02:57 [WARNING] Swoft\Processor\ConsoleProcessor:handle(33) warning
// 2019/05/12-07:02:57 [ERROR] Swoft\Processor\ConsoleProcessor:handle(33) error 

Close message

By default, some startup information is printed to the console at startup.

If your .env has SWOFT_DEBUG=1 turned on, you will see more detailed startup and loading information.

If you want to turn off this information, you can add it in app/Application :

 
    public function getCLoggerConfig(): array
    {
        $config = parent::getCLoggerConfig();
        // Disable print console log
        $config['enable'] = false;

        return $config;
    } 

After modifying the save, restart swowt, you can see that no information will be output.

/docs/2.x/en/log/clog.html
progress-bar