CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • BaseLog
  • ConsoleLog
  • FileLog
  • SyslogLog
  1: <?php
  2: /**
  3:  * CakePHP(tm) :  Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakefoundation.org CakePHP(tm) Project
 12:  * @since         2.2.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Log\Engine;
 16: 
 17: use Cake\Core\InstanceConfigTrait;
 18: use Cake\Datasource\EntityInterface;
 19: use JsonSerializable;
 20: use Psr\Log\AbstractLogger;
 21: 
 22: /**
 23:  * Base log engine class.
 24:  */
 25: abstract class BaseLog extends AbstractLogger
 26: {
 27:     use InstanceConfigTrait;
 28: 
 29:     /**
 30:      * Default config for this class
 31:      *
 32:      * @var array
 33:      */
 34:     protected $_defaultConfig = [
 35:         'levels' => [],
 36:         'scopes' => []
 37:     ];
 38: 
 39:     /**
 40:      * __construct method
 41:      *
 42:      * @param array $config Configuration array
 43:      */
 44:     public function __construct(array $config = [])
 45:     {
 46:         $this->setConfig($config);
 47: 
 48:         if (!is_array($this->_config['scopes']) && $this->_config['scopes'] !== false) {
 49:             $this->_config['scopes'] = (array)$this->_config['scopes'];
 50:         }
 51: 
 52:         if (!is_array($this->_config['levels'])) {
 53:             $this->_config['levels'] = (array)$this->_config['levels'];
 54:         }
 55: 
 56:         if (!empty($this->_config['types']) && empty($this->_config['levels'])) {
 57:             $this->_config['levels'] = (array)$this->_config['types'];
 58:         }
 59:     }
 60: 
 61:     /**
 62:      * Get the levels this logger is interested in.
 63:      *
 64:      * @return array
 65:      */
 66:     public function levels()
 67:     {
 68:         return $this->_config['levels'];
 69:     }
 70: 
 71:     /**
 72:      * Get the scopes this logger is interested in.
 73:      *
 74:      * @return array
 75:      */
 76:     public function scopes()
 77:     {
 78:         return $this->_config['scopes'];
 79:     }
 80: 
 81:     /**
 82:      * Converts to string the provided data so it can be logged. The context
 83:      * can optionally be used by log engines to interpolate variables
 84:      * or add additional info to the logged message.
 85:      *
 86:      * @param mixed $data The data to be converted to string and logged.
 87:      * @param array $context Additional logging information for the message.
 88:      * @return string
 89:      */
 90:     protected function _format($data, array $context = [])
 91:     {
 92:         if (is_string($data)) {
 93:             return $data;
 94:         }
 95: 
 96:         $isObject = is_object($data);
 97: 
 98:         if ($isObject && $data instanceof EntityInterface) {
 99:             return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
100:         }
101: 
102:         if ($isObject && method_exists($data, '__toString')) {
103:             return (string)$data;
104:         }
105: 
106:         if ($isObject && $data instanceof JsonSerializable) {
107:             return json_encode($data, JSON_UNESCAPED_UNICODE);
108:         }
109: 
110:         return print_r($data, true);
111:     }
112: }
113: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs