承接 czim/monolog-json-context 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

czim/monolog-json-context

最新稳定版本:1.0

Composer 安装命令:

composer require czim/monolog-json-context

包简介

JSON Context for Monolog

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status

JSON Context for Monolog

Simple helper package with Monolog formatters.

This helps to set up consistent JSON context log output. The aim of these formatters is to write log lines that may easily be grokked by logstash.

Example Filebeat + Logstash setup

Filebeat configuration

# ... filebeat.prospectors: - type: log enabled: true paths: - /usr/some/path/*.log tail_files: true multiline: pattern: '^\[[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}' negate: true match: after fields: source: context_json index: testing # ...

Logstash configuration

input { beats { port => 5000 } } filter { # Split up the custom message into fields grok { match => { "message" => "\[%{TIMESTAMP_ISO8601:timestamp}\] %{DATA:channel}\.%{LOGLEVEL:severity}: %{GREEDYDATA:context}" } overwrite => [ "message", "context" ] } # Take the timestamp from the log line and use it for @timestamp date { match => [ "timestamp", "yyyy-MM-dd HH:mm:ss" ] } # Clean up (optional) mutate { remove_field => ["timestamp", "prospector", "beat"] } # Pull fields.index up one level, add it so we can use it in the output. # Optional, but I needed this to get `index => "%{index}-%{+YYYY.MM}"` # working for the elasticsearch output. if (![fields][index]) { mutate { add_field => { "index" => "default" } } } else { mutate { add_field => { "index" => "%{[fields][index]}" } remove_field => "[fields][index]" } } # Make sure to interpret the context field as JSON json { source => "context" } } output { elasticsearch { hosts => "elasticsearch:9200" index => "%{index}-%{+YYYY.MM}" } } 

PHP

<?php $formatter = new \Czim\MonologJsonContext\Formatters\JsonContextFormatter(null, 'test-application'); $logger = (new \Monolog\Logger('channel')) ->pushHandler( (new \Monolog\Handler\RotatingFileHandler('/usr/some/path/test.log', 7)) ->setFormatter( ) ); $logger->info('Your message', ['testing' => true, 'category' => 'documentation.test']);

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 87.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固