2015-11-24 27 views
0

在我的節點應用程序中,我使用溫斯頓彈性搜索記錄打印錯誤,我將這些日誌轉儲到彈性搜索。

但我需要一個更多的功能,如果我的彈性搜索羣集關閉,我想將這些日誌轉儲到平面文件。我只是使用這個link


這裏是我寫的代碼
var client = new elasticsearch.Client({localhost:9200}); var logger = new winston.Logger({ exceptionHandlers : [ new Elasticsearch({ json : true, index : 'exception', client : client }) ], exitOnError : false });

我在溫斯頓看過很多文檔,但是我沒有找到任何解決方法。請幫我解決這個問題。Node.js溫斯頓彈性搜索記錄器

+0

你能添加一些代碼?謝謝。 –

回答

0

我無法從文檔中找到方法。

但是,如果你想幹什麼,你能做到這樣:

檢查記錄錯誤。 如果它是有彈性的搜索記錄器錯誤,請將文件傳輸

logger.emitErrs = true; 
logger.on('error', function (err) { 
    // Check err contains msg for Elastic Search Log. 
    // Add File Tansport. 
    // Note* : Please check File Transport exist or not. If exists do not add second time 
}); 
+0

是的,我們可以使用這種方法,但問題是我怎樣才能得到不被傾倒到彈性搜索的日誌。 –

+0

溫斯頓是異步流式傳輸日誌,所以我不認爲這是可能的。確實會有一些日誌的下降。出錯時,您可以添加另一個傳輸,因此從那裏記錄更多日誌 –