0

次のような行を含むテキストファイルがあるとしましょう:

[4/20/11 17:07:12:875 CEST] 00000059 FfdcProvider  W com.test.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on D:/Prgs/testing/WebSphere/AppServer/profiles/ProcCtr01/logs/ffdc/server1_3d203d20_11.04.20_17.07.12.8755227341908890183253.txt com.test.testserver.management.cmdframework.CmdNotificationListener 134
[4/20/11 17:07:27:609 CEST] 0000005d wle           E   CWLLG2229E: An exception occurred in an EJB call.  Error: Snapshot with ID Snapshot.8fdaaf3f-ce3f-426e-9347-3ac7e8a3863e not found.
                             com.lombardisoftware.core.TeamWorksException: Snapshot with ID Snapshot.8fdaaf3f-ce3f-426e-9347-3ac7e8a3863e not found.
   at com.lombardisoftware.server.ejb.persistence.CommonDAO.assertNotNull(CommonDAO.java:70)

これをJSON形式に解析する最も簡単な方法ではないにしても、このようなデータソースをprotovisに簡単にインポートする方法はありますか? たとえば、最初のエントリは次のように解析されます。

[
  {
 "Date": "4/20/11 17:07:12:875 CEST",
 "Status": "00000059",
 "Msg": "FfdcProvider  W com.test.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I",
 },
]

ありがとう、デビッド

4

1 に答える 1

0

Protovis自体は、テキストファイルを解析するためのユーティリティを提供していないため、オプションは次のとおりです。

  • Javascriptを使用して、テキストをオブジェクトに解析します。ほとんどの場合、正規表現を使用します。
  • 選択したテキスト解析言語またはユーティリティを使用してテキストを前処理し、JSONファイルをエクスポートします。

どちらを選択するかは、いくつかの要因によって異なります。

  • データはやや静的ですか、それともデータを見るたびに新しいファイルまたは動的ファイルでこれを実行しますか?静的データの場合、前処理が最も簡単な場合があります。動的データの場合、これにより煩わしい余分な手順が追加される可能性があります。

  • どのくらいのデータがありますか?Javascriptで20Kのテキストファイルを解析することはまったく問題ありません。2MBのファイルの解析は非常に遅く、動作中にブラウザがハングする原因になります(Workersを使用しない場合)。

  • 多くの処理が必要な場合は、サーバー(前処理にサーバー側スクリプトを使用)またはクライアント(ブラウザーで実行)にその負荷をかけますか?

提供したサンプルに基づいて、Javascriptでこれを実行したい場合は、次のように実行できます。

// Assumes var text = 'your text';
// use the utility of your choice to load your text file into the
// variable (e.g. jQuery.get()), or just paste it in.
var lines = text.split(/[\r\n\f]+/),
    // regex to match your log entry beginning
    patt = /^\[(\d\d?\/\d\d?\/\d\d? \d\d:\d\d:\d\d:\d{3} [A-Z]+)\] (\d{8})/,
    items = [],
    currentItem;

// loop through the lines in the file
lines.forEach(function(line) {
    // look for the beginning of a log entry
    var initialData = line.match(patt);
    if (initialData) {
        // start a new item, using the captured matches
        currentItem = {
            Date: initialData[1],
            Status: initialData[2],
            Msg: line.substr(initialData[0].length + 1)
        }
        items.push(currentItem);
    } else {
        // this is a continuation of the last item
        currentItem.Msg += "\n" + line;  
    }
});

// items now contains an array of objects with your data
于 2011-08-05T17:38:24.277 に答える