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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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\Console\ConsoleOutput;
18: use InvalidArgumentException;
19: 
20: /**
21:  * Console logging. Writes logs to console output.
22:  */
23: class ConsoleLog extends BaseLog
24: {
25: 
26:     /**
27:      * Default config for this class
28:      *
29:      * @var array
30:      */
31:     protected $_defaultConfig = [
32:         'stream' => 'php://stderr',
33:         'levels' => null,
34:         'scopes' => [],
35:         'outputAs' => 'see constructor'
36:     ];
37: 
38:     /**
39:      * Output stream
40:      *
41:      * @var \Cake\Console\ConsoleOutput
42:      */
43:     protected $_output;
44: 
45:     /**
46:      * Constructs a new Console Logger.
47:      *
48:      * Config
49:      *
50:      * - `levels` string or array, levels the engine is interested in
51:      * - `scopes` string or array, scopes the engine is interested in
52:      * - `stream` the path to save logs on.
53:      * - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR]
54:      *
55:      * @param array $config Options for the FileLog, see above.
56:      * @throws \InvalidArgumentException
57:      */
58:     public function __construct(array $config = [])
59:     {
60:         if ((DIRECTORY_SEPARATOR === '\\' && !(bool)env('ANSICON') && env('ConEmuANSI') !== 'ON') ||
61:             (function_exists('posix_isatty') && !posix_isatty($this->_output))
62:         ) {
63:             $this->_defaultConfig['outputAs'] = ConsoleOutput::PLAIN;
64:         } else {
65:             $this->_defaultConfig['outputAs'] = ConsoleOutput::COLOR;
66:         }
67: 
68:         parent::__construct($config);
69: 
70:         $config = $this->_config;
71:         if ($config['stream'] instanceof ConsoleOutput) {
72:             $this->_output = $config['stream'];
73:         } elseif (is_string($config['stream'])) {
74:             $this->_output = new ConsoleOutput($config['stream']);
75:         } else {
76:             throw new InvalidArgumentException('`stream` not a ConsoleOutput nor string');
77:         }
78:         $this->_output->setOutputAs($config['outputAs']);
79:     }
80: 
81:     /**
82:      * Implements writing to console.
83:      *
84:      * @param string $level The severity level of log you are making.
85:      * @param string $message The message you want to log.
86:      * @param array $context Additional information about the logged message
87:      * @return bool success of write.
88:      */
89:     public function log($level, $message, array $context = [])
90:     {
91:         $message = $this->_format($message, $context);
92:         $output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message;
93: 
94:         return (bool)$this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level));
95:     }
96: }
97: 
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