回答
可以定義一個custom log format,以讓Apache直接登錄到一個逗號分隔的格式。
你可能有這樣擺弄了一會兒,找到正確的方法。例如,你可能會想使用"
或'
的字段分隔符,以防止域值內的逗號破壞您的CSV。
如果你有,你想看看寫在過去的日誌文件,日誌文件或從Apache的服務器,你沒有訪問配置文件,或者如果您由於某些其他原因不想的問題改變日誌文件格式:
我寫了一個little linux shell sed script是變換默認的Apache日誌文件轉換成可以由自由報辦公室計算讀取的格式:
#!/bin/bash
#reformat apache's access logs, so that they can be interpreted as csv files,
# with space as column delimiter and double quotes to bind together things
# that contain spaces but represent single columns.
# 1) add a doublequote at the begining of the line. first column is the ip adress.
# ip-adresses that have 3 digits in every group but the first could be interpreted as numbers
# with the dots marking groups of thousands.
# 2a) end the ip-adress with quotes
# 2b) surround the second (to me unknown) column thats always just "-" and the
# third column which is the username with quotes
# 2c) reformat the date from "[09/Jul/2012:11:17:47" to "09.Jul 2012 11:17:47"
# 3) remove the string "+0200]" (replace it with doublequotes to end the date column)
# 4) the string that contains the command (5th column) sometimes contains string representation
# of binary rubish. thats no problem as long as this does not contain a doublequote which
# will mess up the column zoning. According to my web searches, csv columns should allow to
# contain doublequotes if they are escaped with a backslash. Although this is the case with
# these problematic strings, Libre Office does not accept it that way. therefore we escape every
# doublequote with a doubleqoute, which is the other valid option according to csv specifications,
# and libre office does accept that one. More technical: we replace every doublequote that does
# neither have a space or another doublequote before it, neither after it, with two doublequotes.
sed \
-e 's/^/"/' \
-e 's/ \([^ ]\{1,\}\) \([^ ]\{1,\}\) \[\([0-9]\{1,2\}\)\/\([a-zA-Z]\{1,3\}\)\/\([0-9]\{1,4\}\):/" "\1" "\2" "\3.\4 \5 /' \
-e 's/ +0200\] /" /' \
-e 's/\([^" ]\)"\([^" ]\)/\1""\2/g'
不太完美的(它不在字段之間不加逗號),但這讓我關閉了。 – 2013-07-12 12:06:32
好,開放式辦公會採取任何你喜歡的分隔符,我在這裏使用的空間。一些csv文件有一個逗號(,)一些有分號(;)它不是標準化的。 – kaefert 2013-07-12 16:10:27
任何機會,你有一個處理的默認的Apache的error.log文件的版本? – snapfractalpop 2015-02-26 22:49:20
- 1. Apache:多個日誌文件?
- 2. Apache grep大日誌文件
- 3. 的logback SLF4J無法獲得日誌報表日誌文件中
- 4. apache日誌文件的條件格式
- 5. 我可以在kubernetes pod中獲得日誌文件嗎?
- 6. 只得到日誌文件
- 7. bash的日誌文件轉換爲CSV
- 8. 創建日誌文件蟒蛇CSV頭
- 9. PowerShell的 - 日誌文件轉換爲CSV
- 10. 將多聯機日誌文件,CSV
- 11. 每秒從Apache日誌文件請求?
- 12. Apache錯誤日誌 - 文件不存在
- 13. 設置Apache日誌文件夾
- 14. 處理日誌文件:Apache Storm或Spark
- 15. 如何將Apache日誌重定向到STDOUT和Apache日誌文件
- 16. Apache獲得403新文件
- 17. apache日誌文件 - 獲取數據修整和過濾
- 18. sphinxQl獲得查詢日誌
- 19. 無法獲得詳細的Apache日誌記錄mod_rewrite
- 20. Apache日誌跟蹤
- 21. Apache日誌設置
- 22. Apache錯誤日誌
- 23. Apache Tomcat Catalina日誌
- 24. 在apache中設置錯誤日誌文件名以包含當前日期
- 25. 如何按日期排序Apache日誌文件?
- 26. 高效的方式來獲得從日誌文件中
- 27. 解析一個日誌文件,並獲得進入數據
- 28. 如何獲得log4j刪除舊的循環日誌文件?
- 29. 如何獲得Tanuki Wrapper日誌文件爲UTF-8編碼?
- 30. 如何使Apache通用日誌記錄寫入特定光盤日誌文件
非常感謝你 – lgt 2012-07-29 08:43:50