- 浏览: 2539253 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
JSON Log in PHP and Cloud Watch(1)JSON Format in PHP
One way to powerful the search in CloudWatch Log is to use Pure JSON in log.
First Step Configure JSON Format Log in PHP
I am using this logging framework in PHP right now
https://github.com/katzgrau/KLogger
So the changes will be similar to this.
<?php
namespace JobConsumerPHP;
require __DIR__ . '/../../vendor/autoload.php';
use \Psr\Log\LogLevel;
use \Katzgrau\KLogger\Logger;
class LoggerUtil
{
private $logger = null;
private $rawJobLogger = null;
private $jobRedisLogger = null;
private $jobSolrLogger = null;
private $jobBackupLogger = null;
public function __construct($ioc)
{
$config = $ioc->getService("config");
$logLevelConfig = $config["loggingLevel"];
$logLevelSystem = getenv('LOGGING_LEVEL');
// default is from config
$logLevel = $logLevelConfig;
if (!empty($logLevelSystem)) {
$logLevel = $logLevelSystem;
}
$logLevelSetting = $this->getLogLevelSetting($logLevel);
$options = array(
'appendContext' => false,
'logFormat' => json_encode([
'datetime' => '{date}',
'logLevel' => '{level}',
'message' => '{message}',
'context' => '{context}',])
);
$this->logger = new Logger('php://stdout', $logLevelSetting, $options);
// 'php://stdout'
$this->rawJobLogger = new Logger('php://stdout', $logLevelSetting, $options);
$this->jobRedisLogger = new Logger('php://stdout', $logLevelSetting, $options);
$this->jobSolrLogger = new Logger('php://stdout', $logLevelSetting, $options);
$this->jobBackupLogger = new Logger('php://stdout', $logLevelSetting, $options);
}
public function getLogLevelSetting($logLevel)
{
$logLevelSetting = null;
switch ($logLevel) {
case 'DEBUG':
$logLevelSetting = LogLevel::DEBUG;
break;
case 'ERROR':
$logLevelSetting = LogLevel::ERROR;
break;
case 'INFO':
$logLevelSetting = LogLevel::INFO;
break;
case 'WARN':
$logLevelSetting = LogLevel::WARNING;
break;
default:
$logLevelSetting = LogLevel::DEBUG;
}
return $logLevelSetting;
}
public function getLogger()
{
return $this->logger;
}
public function getRawJobLogger()
{
return $this->rawJobLogger;
}
public function getJobRedisLogger()
{
return $this->jobRedisLogger;
}
public function getJobSolrLogger()
{
return $this->jobSolrLogger;
}
public function getJobBackupLogger()
{
return $this->jobBackupLogger;
}
}
?>
When we use the logging in our PHP class, it will be similar to this
function convertUnix2DateTime($unixTime)
{
$logger = $this->ioc->getService("logger");
if (is_numeric($unixTime)) {
$logger->debug("convert the unixTime to DateTime", array('unixTime' => $unixTime));
$dateTime = date('Y-m-d\TH:i:s\Z', $unixTime);
} else {
$dateTime = $unixTime;
}
return $dateTime;
}
The output will be
{"datetime":"2017-12-29 21:29:47.276477","logLevel":"DEBUG","message":"convert the unixTime to DateTime","context":"{"unixTime":"1473216774"}"}
{"datetime":"2017-12-29 21:29:47.276699","logLevel":"DEBUG","message":"convert the unixTime to DateTime","context":"{"unixTime":1473216774}"}
Next Step is to deploy this and Try the Search on Cloud Watch
References:
https://github.com/katzgrau/KLogger
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
One way to powerful the search in CloudWatch Log is to use Pure JSON in log.
First Step Configure JSON Format Log in PHP
I am using this logging framework in PHP right now
https://github.com/katzgrau/KLogger
So the changes will be similar to this.
<?php
namespace JobConsumerPHP;
require __DIR__ . '/../../vendor/autoload.php';
use \Psr\Log\LogLevel;
use \Katzgrau\KLogger\Logger;
class LoggerUtil
{
private $logger = null;
private $rawJobLogger = null;
private $jobRedisLogger = null;
private $jobSolrLogger = null;
private $jobBackupLogger = null;
public function __construct($ioc)
{
$config = $ioc->getService("config");
$logLevelConfig = $config["loggingLevel"];
$logLevelSystem = getenv('LOGGING_LEVEL');
// default is from config
$logLevel = $logLevelConfig;
if (!empty($logLevelSystem)) {
$logLevel = $logLevelSystem;
}
$logLevelSetting = $this->getLogLevelSetting($logLevel);
$options = array(
'appendContext' => false,
'logFormat' => json_encode([
'datetime' => '{date}',
'logLevel' => '{level}',
'message' => '{message}',
'context' => '{context}',])
);
$this->logger = new Logger('php://stdout', $logLevelSetting, $options);
// 'php://stdout'
$this->rawJobLogger = new Logger('php://stdout', $logLevelSetting, $options);
$this->jobRedisLogger = new Logger('php://stdout', $logLevelSetting, $options);
$this->jobSolrLogger = new Logger('php://stdout', $logLevelSetting, $options);
$this->jobBackupLogger = new Logger('php://stdout', $logLevelSetting, $options);
}
public function getLogLevelSetting($logLevel)
{
$logLevelSetting = null;
switch ($logLevel) {
case 'DEBUG':
$logLevelSetting = LogLevel::DEBUG;
break;
case 'ERROR':
$logLevelSetting = LogLevel::ERROR;
break;
case 'INFO':
$logLevelSetting = LogLevel::INFO;
break;
case 'WARN':
$logLevelSetting = LogLevel::WARNING;
break;
default:
$logLevelSetting = LogLevel::DEBUG;
}
return $logLevelSetting;
}
public function getLogger()
{
return $this->logger;
}
public function getRawJobLogger()
{
return $this->rawJobLogger;
}
public function getJobRedisLogger()
{
return $this->jobRedisLogger;
}
public function getJobSolrLogger()
{
return $this->jobSolrLogger;
}
public function getJobBackupLogger()
{
return $this->jobBackupLogger;
}
}
?>
When we use the logging in our PHP class, it will be similar to this
function convertUnix2DateTime($unixTime)
{
$logger = $this->ioc->getService("logger");
if (is_numeric($unixTime)) {
$logger->debug("convert the unixTime to DateTime", array('unixTime' => $unixTime));
$dateTime = date('Y-m-d\TH:i:s\Z', $unixTime);
} else {
$dateTime = $unixTime;
}
return $dateTime;
}
The output will be
{"datetime":"2017-12-29 21:29:47.276477","logLevel":"DEBUG","message":"convert the unixTime to DateTime","context":"{"unixTime":"1473216774"}"}
{"datetime":"2017-12-29 21:29:47.276699","logLevel":"DEBUG","message":"convert the unixTime to DateTime","context":"{"unixTime":1473216774}"}
Next Step is to deploy this and Try the Search on Cloud Watch
References:
https://github.com/katzgrau/KLogger
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
发表评论
-
Stop Update Here
2020-04-28 09:00 310I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 465NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 361Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 363Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 328Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 419Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 364Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 444VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 376Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 463NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 413Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 330Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 242GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 443GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 320GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 284Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 302Serverless with NodeJS and Tenc ...
相关推荐
"JsonFormat"在这里指的是一款本地工具,用于帮助开发者更方便地对JSON数据进行格式化,使其更易读。 在Windows环境下,开发者经常需要处理来自服务器的JSON响应或者在代码中创建JSON字符串。"JsonFormat"这款工具...
本文将深入探讨`@JsonFormat`注解的使用,以及它在Jackson库中的作用,特别是与`jackson-annotations.jar`、`jackson-core.jar`和`jackson-databind.jar`这三个核心组件的关系。 首先,让我们了解Jackson的基本构成...
1. **CloudWatch**: AWS CloudWatch是一个全面的服务,用于监控和日志化AWS资源以及自定义应用程序的指标。它提供了报警、日志存储和分析等功能,帮助用户了解他们的系统运行状况。 2. **实时监控**: 实时监控是这...
日常开发中,使用JSON格式的数据情景很多。一开始使用网页的小工具,但用的多了,还是想有一个小工具,能直接快速打开。 支持解析文件 支持解析纯文本,并统计出行列,字符数。提供格式化JSON。 支持搜索,搜索...
editplus格式化 json插件 使用:自定义工具 》命令 》Cscript.exe /nologo "D:\JsonFormat.js" 注意地址需要用引号
1. **格式化**:将混乱的JSON数据进行美化,使其按照标准格式排列,包括缩进和换行,使得数据更易读。 2. **验证**:检查JSON字符串是否符合规范,确保其语法正确无误。 3. **解析与反序列化**:将JSON字符串转换...
1. `encode($data)`: 这个方法可能会接受一个PHP变量作为参数,然后将其转换成JSON格式的字符串。例如,一个关联数组可以被转换为JSON对象,一个数值或字符串数组可以被转换为JSON数组。 ```php class Json { ...
"jQuery JSON with PHP json_encode and json_decode"这个主题涉及到如何利用JSON(JavaScript Object Notation)这一轻量级的数据交换格式,结合PHP的`json_encode`和`json_decode`函数,实现前后端之间的数据通信...
Parsing JSON in Swift will teach you to harness the power of Swift and give you confidence that your app can gracefully handle any JSON that comes its way. You'll learn: - How to use ...
JsonFormat格式化工具,优化调整格式视图,好用速来,
以 JSON 格式将到 先决条件 创建一个日志组,例如: aws logs create-log-group --log-group-name my-log-group 在该组内创建一个日志流 允许这些操作: logs:PutLogEvents和logs:DescribeLogStreams 用法 var ...
1. **自动格式化**:输入一个未格式化的JSON字符串,JsonFormat.exe会自动将其转换为具有缩进和换行的规范格式,使得层次关系一目了然。 2. **高亮显示**:关键值和数据类型可能用不同的颜色高亮,便于快速识别和...
《Python库解析:json_log_decorator-2.0.0》 在编程领域,尤其是Python社区,库是开发者的重要工具,它们提供了预定义的功能,帮助我们更高效地编写代码。今天我们要探讨的是一个名为`json_log_decorator`的Python...
基于Java Swing的json字符串格式化工具,敏捷,高效,即时即用 基于Java Swing的json字符串格式化工具,敏捷,高效,即时即用
JSON++ is a light-weight JSON parser, writer and reader written in C++. JSON++ can also convert JSON documents into lossless XML documents. Contributors http://github.com/hjiang ...
本压缩包"json in java.rar"包含了关于在Java中使用JSON的相关资料,主要可能涵盖了如何将Java对象转换为JSON字符串,以及如何从JSON字符串解析成Java对象。 在Java中,最常用的两个库是Jackson和Gson。Jackson提供...
"vscode 格式化json JsFormat-master.zip" 提供了一个专门针对VSCode的JSON格式化插件——JsFormat。 **JSON(JavaScript Object Notation)** JSON是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器...
一个可以格式化JSON、XML、HTML、以及MAP的toString()打印的字符串的插件,All Format,另外还可以直接生成MD5,方便开发人员调式自己的代码
1. 易于人阅读和编写:JSON使用缩进和换行来增强可读性,使得人类可以直接理解数据的结构。 2. 易于机器解析和生成:JSON格式与JavaScript对象语法高度相似,使得JavaScript可以方便地解析和生成JSON数据。 3. 语言...
1. **JSON序列化**:这个过程是将Java对象转换为JSON字符串。例如,一个Java类实例可以通过`JSONObject`或`Gson`的API将其属性转化为JSON格式。这使得数据可以方便地在网络上传输,因为JSON是文本格式,易于理解和...