[英]Textbox for Logmessages HTML/JS
Before creating an own solution I tried finding something which already suits my needs. 在创建自己的解决方案之前,我尝试找到一些已经满足我需求的东西。 I have got a node.js server where multiple clients / applications connect to. 我有一个node.js服务器,其中有多个客户端/应用程序连接到该服务器。 These clients will send log messages to the server which I would like to display in a panel. 这些客户端会将日志消息发送到服务器,我想在面板中显示该消息。
Now there are some feature I that I need for a typical multiline textbox for logmessages : 现在,我需要一些用于Logmessages的典型多行文本框的功能 :
My question: 我的问题:
Is there already a solution for the above use case? 上面的用例已经有解决方案了吗?
Can I give you my example ? 我可以举一个例子吗? It used to be a textarea
but I've refactored it to a div
with little code changes. 它曾经是一个textarea
但我将其重构为一个div
,几乎没有代码更改。
Some highlights of the code, available on github 代码的一些重点,可以在github上找到
A custom function to send log messages : 一个自定义函数,用于发送日志消息 :
/**
* Add a message to the gamelog
* @param {Object} options : allows custom output
* @param {String} options.message : the message to display
* @param {Boolean} options.isTimed : does the message has a timestamp in front of it?
* @param {Boolean} options.isError : is the message an error?
* @param {Boolean} options.isNewline : start the message on a new line
*/
addMessage: function (options) {
var instance = ns.instance,
audio = instance.audio,
audiofx = audio.settings.fx,
history = this.areaMessage.html();
// isTimed?
options.message = options.isTimed
? history + this.fieldClock.val() + ': ' + options.message
: history + options.message;
// isNewline?
if (options.isNewline) {
options.message = options.message + '<br />';
}
// message
this.areaMessage.html(options.message);
this.scrollTop(this.areaMessage);
// isError?
if (options.isError) {
audio.play(audiofx.error);
}
},
A scroll to top function: 滚动到顶部功能:
/**
* Automatically scroll down (from the top)
* @param {Object} target : jQuery object
*/
scrollTop: function (target) {
target.scrollTop(99999);
target.scrollTop(target.scrollTop() * 12);
}
To use colored messages you should be able to use an HTML string: 要使用彩色消息,您应该能够使用HTML字符串:
log.addMessage({
message: '<span style="color: red;">[ERROR]</span> ',
isNewLine: false
});
log.addMessage({
message: 'the rest of the error message',
isNewLine: true
});
Feel free to use this idea to enroll your own custom message box. 随意使用此想法来注册您自己的自定义消息框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.