Different Yii2 log transports
The preferred way to install this extension is through composer.
php composer.phar require --prefer-dist index0h/yii2-log "0.0.3"
or add line to require section of composer.json
"index0h/yii2-log": "0.0.3"
$emergencyLogFile
, default @app/logs/logService.log
Elasticsearch, Redis and Logstash - are external services, so if they down our logs must be stored in file.
For that ElasticsearchTarget, LogstashTarget, RedisTarget have option $emergencyLogFile
. It's alias to
file where logs will be written on log service is down.
Stores logs in elasticsearch. All logs transform to json, so you can simply watch them by kibana.
Extends yii\log\Target, more options see here
....
'components' => [
'log' => [
'targets' => [
['class' => 'index0h\\log\\ElasticsearchTarget'],
....
index
, default 'yii' - Elasticsearch index name.type
, default 'log' - Elasticsearch index type.componentName
- Name of yii redis component.Extends yii\log\FileTarget, more options see here
....
'components' => [
'log' => [
'targets' => [
['class' => 'index0h\\log\\LogstashFileTarget'],
....
input {
file {
type => "yii_log"
path => [ "path/to/yii/logs/*.log*" ]
start_position => "end"
stat_interval => 1
discover_interval => 30
codec => "json"
}
}
filter {
# ...
}
output {
stdout => {}
}
Extends yii\log\Target, more options see here
....
'components' => [
'log' => [
'targets' => [
['class' => 'index0h\\log\\LogstashTarget'],
// Or UDP.
[
'class' => 'index0h\\log\\LogstashTarget',
'dsn' => 'udp://localhost:3333'
],
// Or unix socket file.
[
'class' => 'index0h\\log\\LogstashTarget',
'dsn' => 'unix:///path/to/logstash.sock'
],
....
input {
tcp {
type => "yii_log"
port => 3333
codec => "json"
}
# Or UDP.
udp {
type => "yii_log"
port => 3333
codec => "json"
}
# Or unix socket file.
unix {
type => "yii_log"
path => "path/to/logstash.sock"
codec => "json"
}
}
filter {
# ...
}
output {
stdout => {}
}
dsn
, default tcp://localhost:3333
- URL to logstash service. Allowed schemas:
tcp, udp, unix - for unix sock files.Extends yii\log\Target, more options see here
....
'components' => [
'log' => [
'targets' => [
['class' => 'index0h\\log\\RedisTarget'],
....
input {
redis {
type => "yii_log"
key => "yii_log"
codec => "json"
}
}
filter {
# ...
}
output {
stdout => {}
}
key
, default yii_log
- Redis list key.componentName
- Name of yii redis component.make test
0.0.3
Comments