LogBack配置

神文学习!!! : https://juejin.im/post/5b51f85c5188251af91a7525#heading-2

巨益log配置参考
monitor.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <included>
  3. <appender name="monitor_time_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
  4. <file>log/time-monitor.log</file>
  5. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  6. <fileNamePattern>log/time-monitor.%d{yyyy-MM-dd}.log</fileNamePattern>
  7. <maxHistory>30</maxHistory>
  8. <totalSizeCap>1GB</totalSizeCap>
  9. </rollingPolicy>
  10. <encoder>
  11. <pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n%ex</pattern>
  12. </encoder>
  13. </appender>
  14. <logger name="monitor.time" level="info" additivity="false">
  15. <appender-ref ref="monitor_time_out"/>
  16. </logger>
  17. </included>

base.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <included>
  3. <include resource="com/greatonce/core/logging/monitor.xml"/>
  4. <property name="es_url_default" value="http://101.37.65.195:40002/_bulk"/>
  5. <property name="log_pattern_default"
  6. value="%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n%ex"/>
  7. <property name="log_file_default" value="log/oms.log"/>
  8. <property name="log_file_pattern_default" value="log/oms.%d{yyyy-MM-dd}.%i.log"/>
  9. <property name="log_file_max_history_default" value="30"/>
  10. <property name="log_file_max_size_default" value="100MB"/>
  11. <property name="log_file_max_total_size_default" value="50GB"/>
  12. <appender name="oms_biz" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  13. <url>${es_url:-${es_url_default}}</url>
  14. <index>biz-logs-%date{yyyy-MM-dd}</index>
  15. <type>oms3</type>
  16. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  17. <connectTimeout>60000</connectTimeout>
  18. <properties>
  19. <property>
  20. <name>host</name>
  21. <value>${HOSTNAME}</value>
  22. </property>
  23. <property>
  24. <name>type</name>
  25. <value>biz</value>
  26. </property>
  27. <property>
  28. <name>logger</name>
  29. <value>%logger</value>
  30. </property>
  31. <property>
  32. <name>thread</name>
  33. <value>%thread</value>
  34. </property>
  35. <property>
  36. <name>bizid</name>
  37. <value>%X{bizid}</value>
  38. </property>
  39. <property>
  40. <name>bizdtl</name>
  41. <value>%X{bizdtl}</value>
  42. </property>
  43. <property>
  44. <name>act</name>
  45. <value>%X{act}</value>
  46. </property>
  47. <property>
  48. <name>oper</name>
  49. <value>%X{oper}</value>
  50. </property>
  51. </properties>
  52. <headers>
  53. <header>
  54. <name>Content-Type</name>
  55. <value>application/json</value>
  56. </header>
  57. </headers>
  58. </appender>
  59. <appender name="oms_product_mall_mapping"
  60. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  61. <url>${es_url:-${es_url_default}}</url>
  62. <index>product-mall-mapping-%date{yyyy-MM-dd}</index>
  63. <type>oms3</type>
  64. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  65. <connectTimeout>60000</connectTimeout>
  66. <properties>
  67. <property>
  68. <name>host</name>
  69. <value>${HOSTNAME}</value>
  70. </property>
  71. <property>
  72. <name>type</name>
  73. <value>biz.product.mall.mapping</value>
  74. </property>
  75. <property>
  76. <name>oper</name>
  77. <value>%X{oper}</value>
  78. </property>
  79. <property>
  80. <name>storeId</name>
  81. <value>%X{storeId}</value>
  82. </property>
  83. <property>
  84. <name>storeName</name>
  85. <value>%X{storeName}</value>
  86. </property>
  87. <property>
  88. <name>mallProductId</name>
  89. <value>%X{mallProductId}</value>
  90. </property>
  91. <property>
  92. <name>mallSkuId</name>
  93. <value>%X{mallSkuId}</value>
  94. </property>
  95. <property>
  96. <name>mallProductOutCode</name>
  97. <value>%X{mallProductOutCode}</value>
  98. </property>
  99. <property>
  100. <name>mallSkuOutCode</name>
  101. <value>%X{mallSkuOutCode}</value>
  102. </property>
  103. </properties>
  104. <headers>
  105. <header>
  106. <name>Content-Type</name>
  107. <value>application/json</value>
  108. </header>
  109. </headers>
  110. </appender>
  111. <appender name="oms_stock_mall_upload"
  112. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  113. <url>${es_url:-${es_url_default}}</url>
  114. <index>stock-upload-%date{yyyy-MM-dd}</index>
  115. <type>oms3</type>
  116. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  117. <connectTimeout>60000</connectTimeout>
  118. <properties>
  119. <property>
  120. <name>host</name>
  121. <value>${HOSTNAME}</value>
  122. </property>
  123. <property>
  124. <name>type</name>
  125. <value>biz.stock.mall.upload</value>
  126. </property>
  127. <property>
  128. <name>batchId</name>
  129. <value>%X{batchId}</value>
  130. </property>
  131. <property>
  132. <name>oper</name>
  133. <value>%X{oper}</value>
  134. </property>
  135. <property>
  136. <name>storeId</name>
  137. <value>%X{storeId}</value>
  138. </property>
  139. <property>
  140. <name>storeName</name>
  141. <value>%X{storeName}</value>
  142. </property>
  143. <property>
  144. <name>productCode</name>
  145. <value>%X{productCode}</value>
  146. </property>
  147. <property>
  148. <name>skuCode</name>
  149. <value>%X{skuCode}</value>
  150. </property>
  151. <property>
  152. <name>status</name>
  153. <value>%X{status}</value>
  154. </property>
  155. <property>
  156. <name>quantity</name>
  157. <value>%X{quantity}</value>
  158. </property>
  159. </properties>
  160. <headers>
  161. <header>
  162. <name>Content-Type</name>
  163. <value>application/json</value>
  164. </header>
  165. </headers>
  166. </appender>
  167. <appender name="oms_stock_sync"
  168. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  169. <url>${es_url:-${es_url_default}}</url>
  170. <index>stock-sync-%date{yyyy-MM-dd}</index>
  171. <type>oms3</type>
  172. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  173. <connectTimeout>60000</connectTimeout>
  174. <properties>
  175. <property>
  176. <name>host</name>
  177. <value>${HOSTNAME}</value>
  178. </property>
  179. <property>
  180. <name>type</name>
  181. <value>biz.stock.sync</value>
  182. </property>
  183. <property>
  184. <name>level</name>
  185. <value>%level</value>
  186. </property>
  187. <property>
  188. <name>batchId</name>
  189. <value>%X{batchId}</value>
  190. </property>
  191. <property>
  192. <name>warehouseId</name>
  193. <value>%X{warehouseId}</value>
  194. </property>
  195. <property>
  196. <name>warehouseCode</name>
  197. <value>%X{warehouseCode}</value>
  198. </property>
  199. <property>
  200. <name>warehouseName</name>
  201. <value>%X{warehouseName}</value>
  202. </property>
  203. <property>
  204. <name>skuCode</name>
  205. <value>%X{skuCode}</value>
  206. </property>
  207. <property>
  208. <name>quantity</name>
  209. <value>%X{quantity}</value>
  210. </property>
  211. </properties>
  212. <headers>
  213. <header>
  214. <name>Content-Type</name>
  215. <value>application/json</value>
  216. </header>
  217. </headers>
  218. </appender>
  219. <appender name="oms_translate_order"
  220. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  221. <url>${es_url:-${es_url_default}}</url>
  222. <index>translate-order-%date{yyyy-MM-dd}</index>
  223. <type>oms3</type>
  224. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  225. <connectTimeout>60000</connectTimeout>
  226. <properties>
  227. <property>
  228. <name>host</name>
  229. <value>${HOSTNAME}</value>
  230. </property>
  231. <property>
  232. <name>type</name>
  233. <value>biz.translate.order</value>
  234. </property>
  235. <property>
  236. <name>level</name>
  237. <value>%level</value>
  238. </property>
  239. <property>
  240. <name>batchId</name>
  241. <value>%X{batchId}</value>
  242. </property>
  243. <property>
  244. <name>tradeId</name>
  245. <value>%X{tradeId}</value>
  246. </property>
  247. <property>
  248. <name>storeId</name>
  249. <value>%X{storeId}</value>
  250. </property>
  251. <property>
  252. <name>storeName</name>
  253. <value>%X{storeName}</value>
  254. </property>
  255. </properties>
  256. <headers>
  257. <header>
  258. <name>Content-Type</name>
  259. <value>application/json</value>
  260. </header>
  261. </headers>
  262. </appender>
  263. <appender name="oms_translate_refund"
  264. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  265. <url>${es_url:-${es_url_default}}</url>
  266. <index>translate-refund-%date{yyyy-MM-dd}</index>
  267. <type>oms3</type>
  268. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  269. <connectTimeout>60000</connectTimeout>
  270. <properties>
  271. <property>
  272. <name>host</name>
  273. <value>${HOSTNAME}</value>
  274. </property>
  275. <property>
  276. <name>type</name>
  277. <value>biz.translate.refund</value>
  278. </property>
  279. <property>
  280. <name>level</name>
  281. <value>%level</value>
  282. </property>
  283. <property>
  284. <name>batchId</name>
  285. <value>%X{batchId}</value>
  286. </property>
  287. <property>
  288. <name>tradeId</name>
  289. <value>%X{tradeId}</value>
  290. </property>
  291. <property>
  292. <name>refundId</name>
  293. <value>%X{refundId}</value>
  294. </property>
  295. <property>
  296. <name>storeId</name>
  297. <value>%X{storeId}</value>
  298. </property>
  299. <property>
  300. <name>storeName</name>
  301. <value>%X{storeName}</value>
  302. </property>
  303. </properties>
  304. <headers>
  305. <header>
  306. <name>Content-Type</name>
  307. <value>application/json</value>
  308. </header>
  309. </headers>
  310. </appender>
  311. <appender name="oms_translate_exchange"
  312. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  313. <url>${es_url:-${es_url_default}}</url>
  314. <index>translate-exchange-%date{yyyy-MM-dd}</index>
  315. <type>oms3</type>
  316. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  317. <connectTimeout>60000</connectTimeout>
  318. <properties>
  319. <property>
  320. <name>host</name>
  321. <value>${HOSTNAME}</value>
  322. </property>
  323. <property>
  324. <name>type</name>
  325. <value>biz.translate.exchange</value>
  326. </property>
  327. <property>
  328. <name>level</name>
  329. <value>%level</value>
  330. </property>
  331. <property>
  332. <name>batchId</name>
  333. <value>%X{batchId}</value>
  334. </property>
  335. <property>
  336. <name>tradeId</name>
  337. <value>%X{tradeId}</value>
  338. </property>
  339. <property>
  340. <name>exchangeId</name>
  341. <value>%X{exchangeId}</value>
  342. </property>
  343. <property>
  344. <name>storeId</name>
  345. <value>%X{storeId}</value>
  346. </property>
  347. <property>
  348. <name>storeName</name>
  349. <value>%X{storeName}</value>
  350. </property>
  351. </properties>
  352. <headers>
  353. <header>
  354. <name>Content-Type</name>
  355. <value>application/json</value>
  356. </header>
  357. </headers>
  358. </appender>
  359. <appender name="oms_dispatch"
  360. class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  361. <url>${es_url:-${es_url_default}}</url>
  362. <index>dispatch-%date{yyyy-MM-dd}</index>
  363. <type>oms3</type>
  364. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  365. <connectTimeout>60000</connectTimeout>
  366. <properties>
  367. <property>
  368. <name>host</name>
  369. <value>${HOSTNAME}</value>
  370. </property>
  371. <property>
  372. <name>type</name>
  373. <value>biz.dispatch</value>
  374. </property>
  375. <property>
  376. <name>level</name>
  377. <value>%level</value>
  378. </property>
  379. <property>
  380. <name>tradeId</name>
  381. <value>%X{tradeId}</value>
  382. </property>
  383. <property>
  384. <name>batchId</name>
  385. <value>%X{batchId}</value>
  386. </property>
  387. <property>
  388. <name>salesOrderCode</name>
  389. <value>%X{salesOrderCode}</value>
  390. </property>
  391. <property>
  392. <name>storeId</name>
  393. <value>%X{storeId}</value>
  394. </property>
  395. <property>
  396. <name>storeName</name>
  397. <value>%X{storeName}</value>
  398. </property>
  399. </properties>
  400. <headers>
  401. <header>
  402. <name>Content-Type</name>
  403. <value>application/json</value>
  404. </header>
  405. </headers>
  406. </appender>
  407. <appender name="oms_mall" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  408. <url>${es_url:-${es_url_default}}</url>
  409. <index>mall-%date{yyyy-MM-dd}</index>
  410. <type>oms3</type>
  411. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  412. <connectTimeout>60000</connectTimeout>
  413. <properties>
  414. <property>
  415. <name>host</name>
  416. <value>${HOSTNAME}</value>
  417. </property>
  418. <property>
  419. <name>type</name>
  420. <value>mall</value>
  421. </property>
  422. <property>
  423. <name>level</name>
  424. <value>%level</value>
  425. </property>
  426. <property>
  427. <name>storeId</name>
  428. <value>%X{storeId}</value>
  429. </property>
  430. <property>
  431. <name>storeName</name>
  432. <value>%X{storeName}</value>
  433. </property>
  434. <property>
  435. <name>apiName</name>
  436. <value>%X{apiName}</value>
  437. </property>
  438. <property>
  439. <name>isSuccess</name>
  440. <value>%X{isSuccess}</value>
  441. </property>
  442. </properties>
  443. <headers>
  444. <header>
  445. <name>Content-Type</name>
  446. <value>application/json</value>
  447. </header>
  448. </headers>
  449. </appender>
  450. <appender name="oms_sms" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  451. <url>${es_url:-${es_url_default}}</url>
  452. <index>sms-%date{yyyy-MM-dd}</index>
  453. <type>oms3</type>
  454. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  455. <connectTimeout>60000</connectTimeout>
  456. <properties>
  457. <property>
  458. <name>host</name>
  459. <value>${HOSTNAME}</value>
  460. </property>
  461. <property>
  462. <name>type</name>
  463. <value>sms</value>
  464. </property>
  465. <property>
  466. <name>level</name>
  467. <value>%level</value>
  468. </property>
  469. <property>
  470. <name>storeId</name>
  471. <value>%X{storeId}</value>
  472. </property>
  473. <property>
  474. <name>storeName</name>
  475. <value>%X{storeName}</value>
  476. </property>
  477. <property>
  478. <name>mobile</name>
  479. <value>%X{mobile}</value>
  480. </property>
  481. <property>
  482. <name>signName</name>
  483. <value>%X{signName}</value>
  484. </property>
  485. <property>
  486. <name>templateCode</name>
  487. <value>%X{templateCode}</value>
  488. </property>
  489. <property>
  490. <name>apiName</name>
  491. <value>%X{apiName}</value>
  492. </property>
  493. <property>
  494. <name>isSuccess</name>
  495. <value>%X{isSuccess}</value>
  496. </property>
  497. <property>
  498. <name>isSmsSendLog</name>
  499. <value>%X{isSmsSendLog}</value>
  500. </property>
  501. </properties>
  502. <headers>
  503. <header>
  504. <name>Content-Type</name>
  505. <value>application/json</value>
  506. </header>
  507. </headers>
  508. </appender>
  509. <appender name="oms_invoice" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  510. <url>${es_url:-${es_url_default}}</url>
  511. <index>invoice-%date{yyyy-MM-dd}</index>
  512. <type>oms3</type>
  513. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  514. <connectTimeout>60000</connectTimeout>
  515. <properties>
  516. <property>
  517. <name>host</name>
  518. <value>${HOSTNAME}</value>
  519. </property>
  520. <property>
  521. <name>type</name>
  522. <value>invoice</value>
  523. </property>
  524. <property>
  525. <name>level</name>
  526. <value>%level</value>
  527. </property>
  528. <property>
  529. <name>storeId</name>
  530. <value>%X{storeId}</value>
  531. </property>
  532. <property>
  533. <name>storeName</name>
  534. <value>%X{storeName}</value>
  535. </property>
  536. <property>
  537. <name>apiName</name>
  538. <value>%X{apiName}</value>
  539. </property>
  540. <property>
  541. <name>isSuccess</name>
  542. <value>%X{isSuccess}</value>
  543. </property>
  544. <property>
  545. <name>templateName</name>
  546. <value>%X{templateName}</value>
  547. </property>
  548. </properties>
  549. <headers>
  550. <header>
  551. <name>Content-Type</name>
  552. <value>application/json</value>
  553. </header>
  554. </headers>
  555. </appender>
  556. <appender name="oms_third_part" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  557. <url>${es_url:-${es_url_default}}</url>
  558. <index>third-part-%date{yyyy-MM-dd}</index>
  559. <type>oms3</type>
  560. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  561. <connectTimeout>60000</connectTimeout>
  562. <properties>
  563. <property>
  564. <name>host</name>
  565. <value>${HOSTNAME}</value>
  566. </property>
  567. <property>
  568. <name>type</name>
  569. <value>third-part</value>
  570. </property>
  571. <property>
  572. <name>level</name>
  573. <value>%level</value>
  574. </property>
  575. <property>
  576. <name>systemName</name>
  577. <value>%X{systemName}</value>
  578. </property>
  579. <property>
  580. <name>systemType</name>
  581. <value>%X{systemType}</value>
  582. </property>
  583. <property>
  584. <name>requestCaller</name>
  585. <value>%X{requestCaller}</value>
  586. </property>
  587. <property>
  588. <name>apiName</name>
  589. <value>%X{apiName}</value>
  590. </property>
  591. <property>
  592. <name>isSuccess</name>
  593. <value>%X{isSuccess}</value>
  594. </property>
  595. </properties>
  596. <headers>
  597. <header>
  598. <name>Content-Type</name>
  599. <value>application/json</value>
  600. </header>
  601. </headers>
  602. </appender>
  603. <appender name="oms_internal" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  604. <url>${es_url:-${es_url_default}}</url>
  605. <index>internal-%date{yyyy-MM-dd}</index>
  606. <type>oms3</type>
  607. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  608. <connectTimeout>60000</connectTimeout>
  609. <properties>
  610. <property>
  611. <name>host</name>
  612. <value>${HOSTNAME}</value>
  613. </property>
  614. <property>
  615. <name>type</name>
  616. <value>internal</value>
  617. </property>
  618. <property>
  619. <name>level</name>
  620. <value>%level</value>
  621. </property>
  622. </properties>
  623. <headers>
  624. <header>
  625. <name>Content-Type</name>
  626. <value>application/json</value>
  627. </header>
  628. </headers>
  629. </appender>
  630. <appender name="file_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
  631. <file>${log_file:-${log_file_default}}</file>
  632. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  633. <fileNamePattern>${log_file_pattern:-${log_file_pattern_default}}</fileNamePattern>
  634. <maxFileSize>${log_file_max_size:-${log_file_max_size_default}}</maxFileSize>
  635. <maxHistory>${log_file_max_history:-${log_file_max_history_default}}</maxHistory>
  636. <totalSizeCap>${log_file_max_total_size:-${log_file_max_total_size_default}}</totalSizeCap>
  637. </rollingPolicy>
  638. <encoder>
  639. <pattern>${log_pattern:-${log_pattern_default}}</pattern>
  640. </encoder>
  641. </appender>
  642. <appender name="sql_file_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
  643. <file>log/sql.log</file>
  644. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  645. <fileNamePattern>log/sql.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  646. <maxFileSize>${log_file_max_size:-${log_file_max_size_default}}</maxFileSize>
  647. <maxHistory>${log_file_max_history:-${log_file_max_history_default}}</maxHistory>
  648. <totalSizeCap>${log_file_max_total_size:-${log_file_max_total_size_default}}</totalSizeCap>
  649. </rollingPolicy>
  650. <encoder>
  651. <pattern>${log_pattern:-${log_pattern_default}}</pattern>
  652. </encoder>
  653. </appender>
  654. <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
  655. <encoder>
  656. <pattern>${log_pattern:-${log_pattern_default}}</pattern>
  657. </encoder>
  658. </appender>
  659. <logger name="com.greatonce.oms" level="info" additivity="false">
  660. <appender-ref ref="file_out"/>
  661. </logger>
  662. <logger name="com.greatonce.oms.bridge.mall.impl.taobao.cloudpush.mappers" level="info"
  663. additivity="false">
  664. <appender-ref ref="sql_file_out"/>
  665. </logger>
  666. <logger name="com.greatonce.oms.dao" level="info" additivity="false">
  667. <appender-ref ref="sql_file_out"/>
  668. </logger>
  669. <logger name="oms.biz.logging" level="info" additivity="false">
  670. <appender-ref ref="oms_biz"/>
  671. </logger>
  672. <logger name="oms.service.logging.stock.mall.upload" level="info" additivity="false">
  673. <appender-ref ref="oms_stock_mall_upload"/>
  674. </logger>
  675. <logger name="oms.service.logging.stock.sync" level="info" additivity="false">
  676. <appender-ref ref="oms_stock_sync"/>
  677. </logger>
  678. <logger name="oms.service.logging.product.mall.mapping" level="info" additivity="false">
  679. <appender-ref ref="oms_product_mall_mapping"/>
  680. </logger>
  681. <logger name="oms.service.logging.translate.order" level="debug" additivity="false">
  682. <appender-ref ref="oms_translate_order"/>
  683. </logger>
  684. <logger name="oms.service.logging.translate.refund" level="debug" additivity="false">
  685. <appender-ref ref="oms_translate_refund"/>
  686. </logger>
  687. <logger name="oms.service.logging.translate.exchange" level="debug" additivity="false">
  688. <appender-ref ref="oms_translate_exchange"/>
  689. </logger>
  690. <logger name="oms.service.logging.dispatch" level="debug" additivity="false">
  691. <appender-ref ref="oms_dispatch"/>
  692. </logger>
  693. <logger name="oms.service.logging.mall" level="info" additivity="false">
  694. <appender-ref ref="oms_mall"/>
  695. </logger>
  696. <logger name="oms.service.logging.sms" level="info" additivity="false">
  697. <appender-ref ref="oms_sms"/>
  698. </logger>
  699. <logger name="oms.service.logging.invoice" level="info" additivity="false">
  700. <appender-ref ref="oms_invoice"/>
  701. </logger>
  702. <logger name="oms.service.logging.thirdPart" level="info" additivity="false">
  703. <appender-ref ref="oms_third_part"/>
  704. </logger>
  705. <logger name="oms.service.logging.internal" level="info" additivity="false">
  706. <appender-ref ref="oms_internal"/>
  707. </logger>
  708. <root level="info">
  709. <appender-ref ref="file_out"/>
  710. </root>
  711. </included>

logback-web-prod.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <property name="log_file" value="log/web.log"/>
  4. <property name="log_file_pattern" value="log/web.%d{yyyy-MM-dd}.%i.log"/>
  5. <property name="es_url" value="http://${es.host}:${es.port}/_bulk"/>
  6. <include resource="com/greatonce/oms/util/logging/base.xml"/>
  7. </configuration>

MDC

参考: https://blog.csdn.net/qq_36801710/article/details/79737359
示例代码:
OmsLogger

  1. package com.greatonce.oms.util.logging;
  2. import com.greatonce.core.util.Assert;
  3. import org.slf4j.Logger;
  4. import org.slf4j.MDC;
  5. /**
  6. * OmsLogger
  7. *
  8. * @author Shenzhen Greatonce Co Ltd
  9. * @author ginta
  10. * @version 2018/4/28
  11. */
  12. public abstract class OmsLogger {
  13. /**
  14. * 获取日志
  15. */
  16. protected abstract Logger getLogger();
  17. private String preProcessMessage(String message) {
  18. return Assert.isEmpty(message) ? "" : message;
  19. }
  20. protected void putMDCItem(String key, Object value) {
  21. if (!Assert.isNull(key) && !Assert.isNull(value)) {
  22. MDC.put(key, String.valueOf(value));
  23. }
  24. }
  25. protected void doInfo(String message, Object... args) {
  26. getLogger().info(preProcessMessage(message), args);
  27. cleanMDC();
  28. }
  29. protected void doWarn(String message, Object... args) {
  30. getLogger().warn(preProcessMessage(message), args);
  31. cleanMDC();
  32. }
  33. protected void doDebug(String message, Object... args) {
  34. getLogger().debug(preProcessMessage(message), args);
  35. cleanMDC();
  36. }
  37. protected void doError(String message, Object... args) {
  38. getLogger().error(preProcessMessage(message), args);
  39. cleanMDC();
  40. }
  41. protected void doError(String message, Throwable throwable) {
  42. getLogger().error(message, throwable);
  43. cleanMDC();
  44. }
  45. protected void doTrace(String message, Object... args) {
  46. getLogger().trace(preProcessMessage(message), args);
  47. cleanMDC();
  48. }
  49. public boolean isTraceEnabled() {
  50. return getLogger().isTraceEnabled();
  51. }
  52. public boolean isDebugEnabled() {
  53. return getLogger().isDebugEnabled();
  54. }
  55. public boolean isInfoEnabled() {
  56. return getLogger().isInfoEnabled();
  57. }
  58. public boolean isWarnEnabled() {
  59. return getLogger().isWarnEnabled();
  60. }
  61. public boolean isErrorEnabled() {
  62. return getLogger().isErrorEnabled();
  63. }
  64. protected void cleanMDC() {
  65. }
  66. }

BizLogger

  1. package com.greatonce.oms.util.logging;
  2. import com.greatonce.oms.domain.enums.OmsModule;
  3. import com.greatonce.oms.util.BizContext;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.slf4j.MDC;
  7. /**
  8. * 业务日志.
  9. *
  10. * @author buer
  11. */
  12. public class BizLogger extends OmsLogger {
  13. public static final String ADD = "新增";
  14. public static final String AUDIT = "审核";
  15. public static final String RESET_AUDIT = "重置审核";
  16. public static final String REVIEW = "复核";
  17. public static final String UPDATE = "修改";
  18. public static final String DELETE = "删除";
  19. public static final String CANCEL = "取消";
  20. public static final String DELIVERY = "发货";
  21. public static final String ENTRY = "入库";
  22. public static final String DISPATCH = "配货";
  23. public static final String AUTO_DISPATCH = "自动配货";
  24. public static final String CANCEL_DISPATCH = "取消配货";
  25. public static final String MALL_DELIVERY = "回传发货";
  26. public static final String MALL_RESET_EXPRESS = "回传快递修改";
  27. public static final String ENABLE = "启用";
  28. public static final String DISABLE = "禁用";
  29. public static final String INVALID = "作废";
  30. public static final String INVALID_DETAIL = "作废明细";
  31. public static final String CONFIM = "确认";
  32. public static final String FINISH = "完结";
  33. public static final String BEGIN = "开始";
  34. public static final String END = "结束";
  35. public static final String NOTICE_WMS = "通知WMS";
  36. public static final String SIGN = "签收";
  37. public static final String SCAN = "扫描";
  38. public static final String THIRD_PART_SYNCHRONIZE = "外部同步";
  39. public static final String POST = "过账";
  40. public static final String TRANSFER = "推送";
  41. public static final String RETURN = "退回";
  42. private static final String BIZ_ID = "bizid";
  43. private static final String DETAIL_ID = "bizdtl";
  44. private static final String ACTION = "act";
  45. private static final String OPER = "oper";
  46. private final Logger logger;
  47. private final String module;
  48. public BizLogger(final OmsModule module) {
  49. this.module = module.toString();
  50. this.logger = getLogger(this.module);
  51. }
  52. public BizLogger(String module) {
  53. this.module = module;
  54. this.logger = getLogger(this.module);
  55. }
  56. private Logger getLogger(String type) {
  57. return LoggerFactory.getLogger("oms.biz.logging." + type.toLowerCase().replace("_", "."));
  58. }
  59. public void log(Long id, Long detailId, String action, String message, Object... args) {
  60. putMDC(id, detailId, action);
  61. this.doInfo(message, args);
  62. }
  63. public void log(Long id, Long detailId, String action) {
  64. log(id, detailId, action, null);
  65. }
  66. public void log(Long id, String action, String message, Object... args) {
  67. log(id, null, action, message, args);
  68. }
  69. public void log(Long id, String action) {
  70. log(id, action, null);
  71. }
  72. public void log(String action, String message, Object... args) {
  73. log(null, action, message, args);
  74. }
  75. protected void putMDC(Long id, Long detailId, String action) {
  76. putMDCItem(BIZ_ID, id);
  77. putMDCItem(DETAIL_ID, detailId);
  78. putMDCItem(OPER, BizContext.getNickname());
  79. putMDCItem(ACTION, action);
  80. }
  81. @Override
  82. protected Logger getLogger() {
  83. return this.logger;
  84. }
  85. @Override
  86. protected void cleanMDC() {
  87. super.cleanMDC();
  88. MDC.remove(BIZ_ID);
  89. MDC.remove(DETAIL_ID);
  90. MDC.remove(ACTION);
  91. MDC.remove(OPER);
  92. }
  93. }

base.xml中片段

  1. <appender name="oms_biz" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
  2. <url>${es_url:-${es_url_default}}</url>
  3. <index>biz-logs-%date{yyyy-MM-dd}</index>
  4. <type>oms3</type>
  5. <errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
  6. <connectTimeout>60000</connectTimeout>
  7. <properties>
  8. <property>
  9. <name>host</name>
  10. <value>${HOSTNAME}</value>
  11. </property>
  12. <property>
  13. <name>type</name>
  14. <value>biz</value>
  15. </property>
  16. <property>
  17. <name>logger</name>
  18. <value>%logger</value>
  19. </property>
  20. <property>
  21. <name>thread</name>
  22. <value>%thread</value>
  23. </property>
  24. <property>
  25. <name>bizid</name>
  26. <value>%X{bizid}</value>
  27. </property>
  28. <property>
  29. <name>bizdtl</name>
  30. <value>%X{bizdtl}</value>
  31. </property>
  32. <property>
  33. <name>act</name>
  34. <value>%X{act}</value>
  35. </property>
  36. <property>
  37. <name>oper</name>
  38. <value>%X{oper}</value>
  39. </property>
  40. </properties>
  41. <headers>
  42. <header>
  43. <name>Content-Type</name>
  44. <value>application/json</value>
  45. </header>
  46. </headers>
  47. </appender>