logstash中将nginxaccess log,转化成json时,发现抛异常。
原因接口的request_body传的事json,但打印日志的时候,json的"转成\x22了,导致日志不是标准 json 格式了。
只需要在日志配置中新增escape=json

nginx.conf 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
log_format aka_logs escape=json
'{"@timestamp":"$time_iso8601",'
'"host":"$hostname",'
'"server_ip":"$server_addr",'
'"client_ip":"222.241.119.99",'
# '"client_ip":"$remote_addr",'
'"xff":"$http_x_forwarded_for",'
'"domain":"$host",'
'"url":"$uri",'
'"referer":"$http_referer",'
'"args":"$args",'
'"upstreamtime":"$upstream_response_time",'
'"responsetime":"$request_time",'
'"request_method":"$request_method",'
'"status":"$status",'
'"size":"$body_bytes_sent",'
'"request_body":"$request_body",'
'"request_length":"$request_length",'
'"protocol":"$server_protocol",'
'"upstreamhost":"$upstream_addr",'
'"file_dir":"$request_filename",'
'"http_user_agent":"$http_user_agent"'
'}';

资料
Module ngx_http_log_module
nginx日志中$request_body 十六进制字符(\x22\x9B\x5C\x09\x08…)完美解决方案
nginx access 日志字符编码问题 \x22

spire.xls版本: 13.10.0

1
2
3
4
5
6
7
8
9
10
11
12
public static void convertExcelToCsvSpire(String sourceFile, String csvFilePath){
//创建Workbook类的对象
com.spire.xls.Workbook workbook = new com.spire.xls.Workbook();
//加载Excel
workbook.loadFromFile(sourceFile);
//计算公式(如果存在)
workbook.calculateAllValue();
//获取第一张工作表sheet
Worksheet sheet = workbook.getWorksheets().get(0);
//保存为CSV
sheet.saveToFile(csvFilePath, ",", Charset.forName("UTF-8"));
}

以上代码在mac中调试的时候,Excel中日期内容为 2023/1/2 12:00:00,另存为csv后日期可以正确转换成2023/1/2 12:00:00,但发布服务器后发现csv保存的日期字段字段为1/2/2023 12:00:00

原因是Spire.xls在保存时会检查当前机器的语言,服务器的默认语言一般是英文,所以 csv 的日期格式被默认转成了英文的日月年格式,将mac的语言调整成语后成功复现。
解决方法就是修改服务的默认语言为中文,加一行Locale.setDefault(Locale.CHINA);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static void convertExcelToCsvSpire(String sourceFile, String csvFilePath){
// 服务器一般为英语,保存CSV的时候会将日期类型转换为 月日年
// 设置为中国则默认为 年月日
Locale.setDefault(Locale.CHINA);
//创建Workbook类的对象
com.spire.xls.Workbook workbook = new com.spire.xls.Workbook();
//加载Excel
workbook.loadFromFile(sourceFile);
//计算公式(如果存在)
workbook.calculateAllValue();
//获取第一张工作表sheet
Worksheet sheet = workbook.getWorksheets().get(0);
//保存为CSV
sheet.saveToFile(csvFilePath, ",", Charset.forName("UTF-8"));
}

资料
xls 转换 pdf时,日期格式的问题。

1
2
3
4
5
6
7
8
9
int expectedInsertions = 100_0000; // 预估数据量
double fpp = 0.0001; // 期望的误差率 0.01%
BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.forName("UTF-8")), expectedInsertions, fpp);

bloomFilter.put("hello world!");

// 判断是否存在,false则表示一定不存在; true表示可能存在
boolean ans = bloomFilter.mightContain("hello world!");
System.out.println(ans);

资料
十亿数据如何去重,红黑树到hash再到布隆过滤器
Google Guava 中布隆过滤器的介绍和使用
Bloom Filter Calculator
Bloom Filter Calculator

  1. 引入jar包
    • Gradle

      1
      implementation "com.carrotsearch:java-sizeof:${javaSizeOf}"
    • Maven

      1
      2
      3
      4
      5
      6
      <!-- https://mvnrepository.com/artifact/com.carrotsearch/java-sizeof -->
      <dependency>
      <groupId>com.carrotsearch</groupId>
      <artifactId>java-sizeof</artifactId>
      <version>0.0.5</version>
      </dependency>
  2. 代码
    1
    2
    String[] arrays = new String[100_0000];
    System.out.println("占用内存:" + RamUsageEstimator.humanSizeOf(arrays));
    执行后输出结果
    1
    占用内存:3.8 MB

先升级Node.js到最新版

这里推荐使用nvm安装最新版node

升级Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
# 安装hexo-cli命令行工具
$ npm install -g hexo-cli

# 安装npm-check
$ npm install -g npm-check
# 检查npm依赖包是否有更新
$ npm-check

# 安装npm包更新工具
$ npm install -g npm-upgrade
# 更新package.json、node-modules
$ npm-upgrade -g
$ npm-upgrade -save
阅读全文 »

tar

解压

1
2
3
4
# 解压到当前目录
$ tar -zxvf apache-kylin-2.6.4-bin-cdh57.tar.gz
# 解压到指定目录(指定命令选项`-C`),如果指定目录不存在,需要先新建目录
$ tar -zxvf apache-kylin-2.6.4-bin-cdh57.tar.gz -C ../Applications

压缩

tar可以保留文件的权限信息

1
$ tar -zcvf kylin-2.5.2.tar.gz kylin

zip

解压

1
$ unzip -o -d /home/sunny myfile.zip

把 myfile.zip 文件解压到 /home/sunny/
-o: 不提示的情况下覆盖文件;
-d: -d /home/sunny 指明将文件解压缩到/home/sunny目录下;

相关资料
为什么 Linux 要用 tar.gz,很少用 7Z 或 ZIP?

1
2
3
4
# chown 用户.用户组 文件名
chown hdfs.hdfs filename
# 递归
chown -R hdfs.hdfs filename

Gradle 常用配置

签名

当程序中使用了第三方的功能,比如分享、地图时,要求程序必须是已签名的
Gradle中配置签名后,可以使我们的Debug也带上签名,而不需要使用Build/Generate Signer Apk去编译带签名的APK

  • build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 在 Android {} 节点下增加
signingConfigs {
signConfig {
storeFile file ('../key.jks')
storePassword '123456'
keyAlias 'xdj'
keyPassword '123456'
}
}
buildTypes {
release {
signingConfig signingConfigs.signConfig
}
debug {
signingConfig signingConfigs.signConfig // 配置debug包的签名
}
}
阅读全文 »

1
2
3
4
5
6
7
8
9
10
# 反向查找依赖树
./gradlew :debt-web:dependencyInsight --dependency mysql-connector-java > reverse.log

# 打印依赖树 https://docs.gradle.org/6.1.1/userguide/viewing_debugging_dependencies.html#sec:listing_dependencies
# https://www.stkent.com/2020/02/04/listing-your-android-apps-actual-dependencies-in-2020.html
# 查看编译时依赖
./gradlew dependencies --configuration compile

# 查看运行时依赖
./gradlew dependencies --configuration runtime

gradle 任务性能监测

./gradlew build –scan

// noinspection GroovyAssignabilityCheck
可取消gradle告警

Gradle系列之从init.gradle说起

buildScript\repositories 区别

1、 buildscript里是gradle脚本执行所需依赖,分别是对应的maven库和插件
2、 allprojects里是项目本身需要的依赖,比如我现在要依赖我自己maven库的toastutils库,那么我应该将maven {url ‘https://dl.bintray.com/calvinning/maven'}写在这里,而不是buildscript中,不然找不到。

pluginManagement 似乎又出了个新标签

资料
Gradle | allprojects ,根 repositories 区别是什么?

0%