のためにあなたがチャンネルでこれを達成することができ、このログ(users.log)特定のファイルに保存されます。
カスタムチャネルを作成できました(この場合はuser_channel
)。 user_channel
のログレコードのみを扱うハンドラuser_handler
が作成されます。コントローラでは、チャンネルの特定のロガーが要求されます。このロガーで記録されたものはすべてuser_channel
になります。 は、そのメッセージだけをログファイルに入れます。
# app/config/config.yml
monolog:
channels: ['user_channel']
handlers:
user_handler:
level: debug
type: stream
path: '%kernel.logs_dir%/user.log'
channels: ['user_channel']
main:
level: debug
type: stream
path: '%kernel.logs_dir%/log.log'
channels: ['!user_channel'] #In case you don't want other handler to receive user_channel messages
次に、ログハンドラに直接アクセスできます。
public function indexAction(){
$logger = $this->get('monolog.logger.user_channel');
$logger->debug('User {X} is logout');
}
ログエンティティは'%kernel.logs_dir%/user.log'
に書き込まれます。