Last active
May 22, 2018 02:07
-
-
Save saiseisei/338ab38832eaac981f400426d02de949 to your computer and use it in GitHub Desktop.
【PHP】composer+cakePHP+log4php開発環境構築手順 ref: https://qiita.com/Chelsea/items/88f97cd60234fe3ea021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[2018/02/28 13:59:57.427] [APP][INFO ] ログ確認 | |
[2018/02/28 13:59:57.427] [APP][DEBUG] ログ確認 | |
[2018/02/28 13:59:57.427] [APP][ERROR] ログ確認 | |
[2018/02/28 13:59:57.427] [APP][WARN ] ログ確認 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 下記の環境設定レベル切り替え用のソースコードを追加 | |
/** | |
* Environment Level: | |
* | |
* develop | |
* release | |
* | |
*/ | |
'Env' => 'develop', // ローカル用 | |
/*'Env' => 'release', */ // リリース用 | |
/** | |
* Configures logging options | |
*/ | |
'Log' => [ | |
# 下記のAppログ設定のソースコードを追加 | |
'app' => [ | |
'className' => 'App', | |
'model' => 'LogEntry', | |
'path' => LOGS, | |
'file' => 'debug', | |
'url' => env('LOG_DEBUG_URL', null), | |
'scopes' => false, | |
'levels' => ['debug', 'info', 'warn', 'error', ], | |
], | |
'debug' => [ | |
'className' => 'Cake\Log\Engine\FileLog', | |
'path' => LOGS, | |
'file' => 'debug', | |
'url' => env('LOG_DEBUG_URL', null), | |
'scopes' => false, | |
'levels' => ['notice', 'info', 'debug'], | |
], | |
'error' => [ | |
'className' => 'Cake\Log\Engine\FileLog', | |
'path' => LOGS, | |
'file' => 'error', | |
'url' => env('LOG_ERROR_URL', null), | |
'scopes' => false, | |
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], | |
], | |
// To enable this dedicated query log, you need set your datasource's log flag to true | |
'queries' => [ | |
'className' => 'Cake\Log\Engine\FileLog', | |
'path' => LOGS, | |
'file' => 'queries', | |
'url' => env('LOG_QUERIES_URL', null), | |
'scopes' => ['queriesLog'], | |
], | |
], | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Logger; | |
public function index() | |
{ | |
// getLoggerにlog4php.xmlに定義したlogger nameをセットする | |
$logger = Logger::getLogger('APP'); | |
$logger->info( 'ログ確認' ); | |
$logger->debug( 'ログ確認' ); | |
$logger->error( 'ログ確認' ); | |
$logger->warn( 'ログ確認' ); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app.phpを呼ぶ処理(既存のまま) | |
try { | |
Configure::config('default', new PhpConfig()); | |
Configure::load('app', 'default', false); | |
} catch (\Exception $e) { | |
exit($e->getMessage() . "\n"); | |
} | |
# 下記のソースコードを追加 | |
// log4phpを格納した場所(C:\xampp\htdocs\App\vendor\apache\log4php) | |
require(ROOT . DS . 'vendor' . DS . 'apache' . DS . 'log4php' . DS . 'Logger.php'); | |
try { | |
$env = Configure::read('Env'); | |
if ($env === 'release') { | |
Logger::configure ( ROOT . DS . 'config' . DS . 'log4php_release.xml' ); | |
} else { | |
Logger::configure ( ROOT . DS . 'config' . DS . 'log4php_develop.xml' ); | |
} | |
} catch (\Exception $e) { | |
die($e->getMessage() . "\n"); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 追加行:"apache/log4php": "2.3.0" | |
"require": { | |
"php": ">=5.6", | |
"cakephp/cakephp": "3.5.*", | |
"cakephp/migrations": "^1.0", | |
"cakephp/plugin-installer": "^1.0", | |
"josegonzalez/dotenv": "2.*", | |
"mobiledetect/mobiledetectlib": "2.*", | |
"apache/log4php": "2.3.0" | |
}, | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd C:\xampp\php | |
composer -V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd C:\xampp\php | |
php composer.phar create-project --prefer-dist cakephp/app C:\xampp\htdocs\App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<projectDescription> | |
<name>App</name> | |
<comment></comment> | |
<projects> | |
</projects> | |
<buildSpec> | |
</buildSpec> | |
<natures> | |
</natures> | |
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# App | |
Alias /App "C:/xampp/htdocs/App" | |
<Directory "C:/xampp/htdocs/App"> | |
order deny,allow | |
Allow from all | |
Require all granted | |
</Directory> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<configuration xmlns="http://logging.apache.org/log4php/"> | |
<appender name="default" class="LoggerAppenderConsole"> | |
<layout class="LoggerLayoutPattern"> | |
<param name="conversionPattern" value="[%date{Y/m/d H:i:s.u}] [%logger][%-5level] %msg%n" /> | |
</layout> | |
</appender> | |
<!-- APP用 --> | |
<appender name="appAppender" class="LoggerAppenderDailyFile"> | |
<param name="file" value="C:\xampp\htdocs\App\logs\APP.%s.log" /> | |
<param name="datePattern" value="Ymd" /> | |
<layout class="LoggerLayoutPattern"> | |
<param name="conversionPattern" value="[%date{Y/m/d H:i:s.u}] [%logger][%-5level] %msg%n" /> | |
</layout> | |
</appender> | |
<!-- APP用 --> | |
<logger name="APP"> | |
<level value="debug" /> | |
<appender_ref ref="appAppender" /> | |
</logger> | |
</configuration> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment