public function test_formatMessage()
 {
     //txt, lvl, category, timestamp
     $message = ['some message', Logger::LEVEL_INFO, 'app', (new \DateTime('2001-02-03 04:05:06'))->getTimestamp() + 0.12345];
     $ft = new \yii\log\FileTarget(['logFile' => '@app/runtime/logs/log.txt']);
     $ft_my = new FileTarget(['logFile' => '@app/runtime/logs/log_my.txt']);
     $this->assertEquals('2001-02-03 04:05:06 [info][app] some message', $ft->formatMessage($message));
     //yii2 default
     $ft_my->with_microtime = false;
     $this->assertEquals('2001-02-03 04:05:06 [info][app] some message', $ft_my->formatMessage($message));
     //mylib as yii2 default
     $ft_my->with_microtime = true;
     $this->assertEquals('2001-02-03 04:05:06:123450 [info][app] some message', $ft_my->formatMessage($message));
     //mylib custom with 6 nums pad
 }
Exemple #2
0
<?php

// Docs links:
// 1) https://github.com/yiisoft/yii2/blob/master/docs/guide/concept-configurations.md
// 2) https://github.com/yiisoft/yii2/blob/master/docs/guide/structure-controllers.md#default-controller-
use yii\helpers\ArrayHelper;
use common\components\log\AppLogger;
$params = ArrayHelper::merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
$config = ['id' => 'app-frontend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'frontend\\modules\\site\\controllers', 'controller' => '@frontend/modules/site/IndexController', 'defaultRoute' => 'site/index/index', 'layout' => '@frontend/layouts/main.php', 'modules' => ['site' => frontend\modules\site\Module::className(), 'profile' => frontend\modules\profile\Module::className()], 'components' => ['urlManager' => $params['app.urlManager.localeUrls'], 'urlManagerBackend' => $params['app.urlManagerBackend'], 'view' => $params['app.view'], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => ['file' => ['class' => yii\log\FileTarget::className(), 'levels' => ['error', 'warning']], 'dbLogger' => ['class' => common\components\log\AppLoggerDbTarget::className(), 'levels' => ['info', 'error', 'warning'], 'logVars' => ['_GET', '_POST'], 'categories' => [AppLogger::CATEGORY_APPLICATION, AppLogger::CATEGORY_TEST, AppLogger::CATEGORY_FRONTEND, AppLogger::CATEGORY_PROFILE, AppLogger::CATEGORY_SITE], 'logTable' => 'log']]], 'errorHandler' => ['class' => yii\web\ErrorHandler::className(), 'errorAction' => 'site/index/error']], 'params' => $params];
if (YII_ENV_DEV) {
    $config['modules']['test'] = frontend\modules\test\Module::className();
}
return $config;
Exemple #3
0
<?php

// @see https://github.com/yiisoft/yii2/blob/master/docs/guide/concept-configurations.md
use yii\helpers\ArrayHelper;
use common\components\log\AppLogger;
$params = ArrayHelper::merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
$config = ['id' => 'app-console', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'console\\controllers', 'controllerMap' => ['message' => console\controllers\MessageController::className()], 'modules' => [], 'components' => ['i18n' => $params['app.i18n'], 'log' => ['targets' => ['file' => ['class' => yii\log\FileTarget::className(), 'levels' => ['error', 'warning']], 'dbLogger' => ['class' => common\components\log\AppLoggerDbTarget::className(), 'levels' => ['info', 'error', 'warning'], 'logVars' => ['_GET', '_POST'], 'categories' => [AppLogger::CATEGORY_CONSOLE], 'logTable' => 'log']]]], 'params' => $params];
// configuration adjustments for 'dev' environment
if (!YII_ENV_TEST && !YII_ENV_PROD) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = $params['app.giiModule'];
}
return $config;
Exemple #4
0
<?php

// Docs links:
// 1) https://github.com/yiisoft/yii2/blob/master/docs/guide/concept-configurations.md
// 2) https://github.com/yiisoft/yii2/blob/master/docs/guide/structure-controllers.md#default-controller-
use yii\helpers\ArrayHelper;
use common\components\log\AppLogger;
use common\rbac\AccessControl;
$params = ArrayHelper::merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
$config = ['id' => 'app-backend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'backend\\modules\\backend\\controllers', 'controller' => '@backend/modules/backend/IndexController', 'defaultRoute' => 'backend/index/index', 'layout' => '@backend/layouts/main.php', 'modules' => ['backend' => backend\modules\backend\Module::className(), 'i18n' => ['class' => uran1980\yii\modules\i18n\Module::className(), 'controllerMap' => ['default' => uran1980\yii\modules\i18n\controllers\DefaultController::className()], 'as access' => ['class' => AccessControl::className(), 'rules' => [['controllers' => ['i18n/default'], 'actions' => ['index', 'save', 'update', 'rescan', 'clear-cache', 'delete', 'restore'], 'allow' => true, 'roles' => [AccessControl::ROLE_TRANSLATOR]]]]]], 'components' => ['urlManager' => $params['app.urlManager.localeUrls'], 'urlManagerFrontend' => $params['app.urlManagerFrontend'], 'view' => $params['app.view'], 'user' => ['class' => yii\web\User::className(), 'identityClass' => common\models\identity\UserIdentity::className(), 'enableAutoLogin' => true, 'loginUrl' => '/backend/login'], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => ['file' => ['class' => yii\log\FileTarget::className(), 'levels' => ['error', 'warning']], 'dbLogger' => ['class' => common\components\log\AppLoggerDbTarget::className(), 'levels' => ['info', 'error', 'warning'], 'logVars' => ['_GET', '_POST'], 'categories' => [AppLogger::CATEGORY_APPLICATION, AppLogger::CATEGORY_TEST, AppLogger::CATEGORY_BACKEND], 'logTable' => 'log']]], 'errorHandler' => ['class' => yii\web\ErrorHandler::className(), 'errorAction' => 'backend/index/error']], 'params' => $params];
return $config;