Using
Lua scripts within TailExpert can be very powerfull. The Lua
scripting engine in TailExpert not only provides you the standard
lua library functionality but the Lua scripting engine has also
access to the full .NET runtime environment by means of the
integration of luainterface. Besides that LogTail also adds two
graphing libraries which one can use to paint graphs based upon
matches detected in the logmessages. Additionaly TailEpert also
provides a number of functions to the scripting engine to automate
some tasks line setting filters, notifications etc. imagine that
you have a system that throws enormous amounts of logmessages and
when the part your interrested in arrives your logfile is so large
that analysing it is painfull. In this case you could automate this
job by adding a lua script that filters all logmessages until an
event arrives then switches the filter off and stops the log tail
when the interresting part has been captured. Or you want to
capture a sequence of events. Or you just want to capture a
temperature logged and see this is a graph, lua scripts can do it
for you.
Using
Tailexpert internal functions
TailExpert
exposes to following functions to lua scripts to control the
application.
PrintLine(string
line) - print logmessage to active tab
PrintLines(LuaTable table) - print multiple logmessages to
active tab
PrintStatusLine(string line) - print message to status
bar
LogMessage(int severity, string message) - print a
logmessage to TailExpert log file (defaults to
C:\Temp\TailExpert.log)
string GetDateTimeString(string format) - get the current
date/time formatted in given format (see .NET documentation on
format sepcifiers)
AddPluginMenuEntry(ToolStripMenuItem item) - add a menu
entry in the plugins menu
RemovePluginMenuEntry(ToolStripMenuItem item) - remove
specified menu entry from plugins menu
string AddFilter(string tabName, string find, string column,
string operation, bool invert, bool matchCase, bool regEx) - add
filter to specified tab, returns a guid that identifies filter
RemoveFilter(string tabName, string guid) - remove filter
specified with guid from specified tab
ActivateFilter(string tabName, string guid, bool active) -
activate filter specified with guid on specified tab
string AddTranslate(string tabName, string find, string
column, string operation, bool invert, bool matchCase, bool regEx)
- add translation to specified tab, returns a guid that identifies
translation
RemoveTranslate(string tabName, string guid) - remove
translation specified with guid from specified tab
ActivateTranslate(string tabName, string guid, bool active)
- activate translation specified with guid on specified tab
string AddNotification(string tabName, string find, string
column, string operation, bool invert, bool matchCase, bool regEx)
- add notification to specified tab, returns a guid that identifies
notification
RemoveNotification(string tabName, string guid) - remove
notification specified with guid from specified tab
ActivateNotification(string tabName, string guid, bool
active) - activate notification specified with guid on specified
tab
Pause(string tabName, boolean pause, boolean discard) -
pause/run log, discard: discard incoming messages when paused
LockScroll(string tabName, boolean lockScroll) - lock
scroll
int GetLastIndex(string tabName) - get last rowindex from
specified tab
SelectLogLines(string tabName, int begin, int end) - select
logmessages from specified tab from begin to end
SaveSelectedLogLines(string tabName, string filename, string
encoding, bool lineNumbers) - save selected loglines from specified
tab to file
SaveLog(string tabName, string filename, string encoding,
bool lineNumbers) - save complete log from specified tab to
file
OpenFileTab(string filename, bool addTimeStamp, bool pauzed)
- open a file tab on specified filename
OpenEventLogTab(string eventLogName, bool addTimeStamp, bool
pauzed) - open tab on specified event log
OpenSysLogTab(string tabName, int port, bool addTimeStamp,
bool pauzed, bool saveToFile, string filename) - open tab on
specified UDP port
OpenSerialLogTab(string tabName, string portName, string
baud, string bits, string stop, string parity, string handshake,
bool addTimeStamp, bool pauzed, bool saveToFile, string filename) -
open tab on specified serial port
string GetActiveTab() - get the active (visible) tab
SelectTab(String tabName) - select the active (visible)
tab
CloseTab(string tabName) - close selected tab
List<string> GetTabNames() - get list op opened
tabs
ClearTab(string tabName) - clear tab contents
ReloadTab(string tabName) - reload tab from file
RefreshTab(string tabName) - refresh tab content from
internal cache
In the example code below
some of the mentioned functions are used, a logfile is opened and a
filter gets installed on this logfile. In the OnEnter() function a
new tab is openend in the logview using the OpenFileTab function
and next a filter is added using the AddFilter() function.
Code:
--[[
This is an example script for the lua engine in
TailExpert
Purpose:
This script will add a filter to an already opened
tab and activate it
]]--
require("Config")
-- Import WIndows Assemblies
import("System")
import("System.Windows.Forms")
import("System.Drawing")
import("System.Drawing.Drawing2D")
function click()
local filter = AddFilter("TailExpert.log", "Add
Filter", ALLCOLUMNS, CONTAINS, false, false, false)
ActivateFilter("TailExpert.log", filter, true)
end
--[[
Required predefined functions: Are called from TailExpert, adapt to
your needs
]]--
function OnEvaluate(loglines)
-- Do not put LogMessage() here this will overflow
your logs as
-- Evaluate is called every tail cycle
-- If you need log make sure it's not output every
cycle
-- if ScriptInitialized == true then
-- end
end
function OnEnter()
ScriptInitialized = true
LogMessage(INFO, "InstallFilter.lua script
OnEnter()")
OpenFileTab("c:\\temp\\TailExpert.log", false,
false)
dropDownItem = ToolStripMenuItem()
dropDownItem.Text = "TestPlugin"
dropDownItem.Click:Add(click)
AddPluginMenuEntry(dropDownItem)
-- tests the functions above
ScriptInitialized = true
end
function OnExit()
LogMessage(INFO, "InstallFilter.lua script
OnExit()")
ScriptInitialized = false -- prevent
Evaluate to be called
if (dropDownItem ~= nill) then
RemovePluginMenuEntry(dropDownItem)
end
end