@yumilen said in Лайфхаки BAS:
@fox Немного пошаманил тут над вашими сорсами и написал универсальный log_html()
Интересный вариант, редко на форуме встретишь красивый, качественный код.
Только в файле лога будет неразбериха:

ни каких опозновательных данных:

Потому что в функции log_html() два атрибута:
log_html("<span style='color:yellow'>ТЕКСТ который отображается в логе</span>","ТЕКСТ который записывается в файл лога")
а вы записываете в лог только текст:
Logger.WriteHtml(logHtml, text);
Функция, также, как и обычный log() выводит айдишник экшина с той лишь разницей, что он не кликабельный.
Чтобы id был кликабельным, можно указать на него ссылку:
log_html("<a href='action://action366852852' style='color:gray;'>[366852852]</a>")
Вот версия вашей функции с кликабельным id и обычной информацией в текстовом логе:
/** _LogHTML()
*
* @param [mix] text - text to log
* @param [string] color - text color
* @param [string|Array|Object] define - print parameters
* Empty define print all data
* [strijng] ('id, time, thread'), empty string, print only text
* [Array] (['id', 'time', 'thread']), empty array, print only text
* [Object] ({id: true, time: true, thread: true}), empty object, print only text
* @example ({id: false, time: false, thread: false} == {}),
* @example ({id: true, time: false, thread: false} == {id: true})
*/
function _LogHTML(text, color, define){
var id, time, thread, logHtml, textLog;
define = (typeof define == 'string') ? define.split(/[\s,.|:;]+/g) : define;
if(typeof define === 'object' && define !== null){
if(Array.isArray(define)){
id = define.indexOf('id') > -1;
time = define.indexOf('time') > -1;
thread = define.indexOf('thread') > -1;
}
else{
id = define.id == true;
time = define.time == true;
thread = define.thread == true;
}
}
else id = time = thread = true;
id = id ? '<a href="action://action' + ScriptWorker.GetCurrentAction() + '" style="color:gray;">[' + ScriptWorker.GetCurrentAction() + ']</a>' : '';
time = time ? ' ' + getTime() : '';
thread = thread ? ' Поток №' + thread_number() : '';
logHtml = (id || time || thread) ? id + '<span style="color: white">' + time + thread + ' : </span>' : '';
logHtml += '<span style="color:' + (color ? color : 'white') + '">' + text + '</span>';
textLog = '[' + ScriptWorker.GetCurrentAction() + ']' + time + thread + ' : ' + text
function getTime(){
var checkTime = function(i){ return (i < 10) ? "0" + i : i; };
var d = new Date();
var hh = checkTime(d.getHours());
var mm = checkTime(d.getMinutes());
var ss = checkTime(d.getSeconds());
return '[' + hh + ':' + mm + ':' + ss + ']';
};
Logger.WriteHtml(logHtml, textLog);
}


Вот тестовый скрипт