//v0.3 - o5/2o15 //- first released version //v0.4 - o5/2o15 //- workaround for Script.Config not always being present //v0.5 - o2/2o16 //- Log() function update to latest version (case-insensitive options) //- script config items and options slighty renamed (not affecting behaviour) /////////////////////////////////////////////////////////////////////////////// function OnInit(data){ //uid added via script wizard (do not change after publishing this script) var uid = "DF939B94-8979-491A-82C1-96CB041B12F9"; //resource center url added via script wizard (required for updating) var url = "http://resource.dopus.com/viewtopic.php?f=35&t=24564"; data.name = "Xtra.Demo: XLogDemo"; data.log_prefix = "XLogDemo"; data.desc = "XLog Demonstration"; data.copyright = "tbone"; data.version = "0.5"; data.min_version = "11.5"; data.default_enable = true; var cmd = data.AddCommand(); cmd.name = "XLogDemo"; cmd.method = "Command_XLogDemo"; cmd.desc = data.desc; cmd.label = "XLogDemo"; cmd.template = "XLOG/O[off,xception,error,warning,info,,trace,dump,all]"; /////////////////////////////////////////////////////////////////////////// function ConfigHelper(data){ //v1.2 var t=this; t.d=data; t.c=data.config; t.cd=DOpus.Create.Map(); t.add=function(name, val, des){ t.l={n:name,ln:name. toLowerCase()}; return t.val(val).des(des);} t.des=function(des){ if (!des) return t; if (t.cd.empty) t.d.config_desc=t.cd; t.cd(t.l.n)=des; return t;} t.val=function(val){ var l=t.l; if (l.v!==l.x&&typeof l.v=="object") l.v.push_back(val);else l.v=t.c[l.n]=val;return t;} t.trn=function(){return t.des(t("script.config."+t.l.ln));}} /////////////////////////////////////////////////////////////////////////// var cfg = new ConfigHelper(data); cfg.add('XLog', DOpus.Create.Vector()). val(5). //first value is the default index for dropdown selections like this val("Off").val("Xception").val("Error").val("Warning").val("Info").val("Normal").val("Trace").val("Dump").val("All"). des('Console output level. The higher, the more output will be visible in the console window. '); } /////////////////////////////////////////////////////////////////////////////// var COMMAND_FAILURE = true; var COMMAND_USERABORT = true; var COMMAND_BADPARAMS = true; var COMMAND_SUCCESS = false; /////////////////////////////////////////////////////////////////////////////// //uncomment to override the DO global XLog setting (XLog in DOpus.Vars) //XLogForce = true; /////////////////////////////////////////////////////////////////////////////// function Command_XLogDemo(data){ //DOpus.ClearOutput(); //command line switch XLOG present? if (data.func.args.got_arg.XLOG){ //create a global XLog variable with the incoming value //notice that you need to setup "XLog" before the first use of Log(), //else the value from Script.Config.XLog will be used XLog = data.func.args["XLOG"]; DOpus.Output("Using command line XLog-level ["+XLog+"]..
"); } else { //using XLog logging defaults from the script config or from the //global setting (XLog in DOpus.Vars) if XLogForce is not set } //printing full commandline if "dump" level Log("CmdLine:" + data.cmdline, "D"); //let's start with a "trace" information, raising indentation //by 1, because the actual body of this function follows Log("Command_XLogDemo():", 'T', 1); //run something var result = OutputXLogDetails(data); //functions comes to an end, decrease indentation Log("Command_XLogDemo() - END", 'T', -1); //intendation back to zero Log("End of Demo."); return COMMAND_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// function OutputXLogDetails(data) { //start of a new function, increase "trace" indentation Log("OutputXLogDetails():", 'T', 1); Log("This is a regular message"); //print some informational and "dumpy" type of messages Log("Global XLog exists: " + DOpus.Vars.Exists("XLog"), "I"); Log(" value : " + (DOpus.Vars.Exists("XLog") && DOpus.Vars.Get("XLog")), "D"); Log("Config XLog exists: " + (Script.Config["XLog"]!=undefined), "I"); Log(" value : " + (Script.Config["XLog"]!=undefined && Script.Config["XLog"]), "D"); Log("Cmdlne XLog exists: " + data.func.args.got_arg["XLOG"], "I"); Log(" value : " + data.func.args["XLOG"], "D"); //notice: "XLog" will always exist, after the first call to Log() Log("Script XLog exists: " + (XLog!=undefined) + " - will always be true after first call to Log()", "W"); Log(" indents: " + XLog.I, "D"); Log(" level : " + XLog.L, "D"); Log(" paused : " + XLog.paused, "D"); var result = MySubRoutine(); if (result==null) //whoo, something bad happend, let's output an exception type message Log("An error occured, MySubRoutine() returned null!", 'X'); //end of function reached, decrease indentation Log("OutputXLogDetails() - END", 'T', -1); return COMMAND_SUCCESS } /////////////////////////////////////////////////////////////////////////////// function MySubRoutine() { //start of function, increase indentation Log("MySubRoutine():", 'T', 1); var param01 = true; var param02 = false; //some dump messages Log("PARAM 01: " + param01, 'D'); Log("PARAM 02: " + param02, 'D'); var result = null; //informational "return" message Log("Returning: " + result, 'I'); //end of function, decrease indentation without printing anything Log("-", 'T', -1); return result; } /////////////////////////////////////////////////////////////////////////////// //Attention: DEMONSTRATIONAL XLOG VARIANT WITH "UNCONTROLLED" OUPTUT! //Please use the function from the forums post or the one following //for "production" use (and rename to "Log" as well of course). /////////////////////////////////////////////////////////////////////////////// function Log(text, lvl, ind){ //XLog v0.42 (non-casesensitive options) var u,lvs={o:0,x:1,e:2,w:3,i:4,n:5,t:6,d:7,a:8},i=["","X","E","W","I","","","",""]; if (typeof XLog==(u="undefined")){var v=DOpus.Vars; if (v.Exists("XLog") && typeof XLogForce==u) { DOpus.Output("XLogForce not present"); DOpus.Output("Using global Vars.XLog-level..
"); XLog=v.Get("XLog"); }} if (typeof XLog==u){var c=Script.Config; if(typeof c!="undefined" && typeof c.XLog!=u){ DOpus.Output("Using Script.Config.XLog-level..
"); XLog=c.XLog; }} if (typeof XLog==u){DOpus.Output("Using default level..
"); XLog="normal";} if(XLog.paused===undefined){ if(XLog===true) var L=5; else if(!isNaN(parseInt(XLog,10))) var L=XLog*1; else var L=lvs[(""+XLog).toLowerCase().substring(0,1)]; XLog={paused:false,I:0,L:L};} lvl=(lvl==undefined?5:lvs[lvl.substring(0,1).toLowerCase()]); if (!(lvl && XLog.L && !XLog.paused && (lvl<=XLog.L))){ return;} var pad = (XLog.I==0?"":new Array(XLog.I+1).join(" ")); if (i[lvl])pad = i[lvl]+(!pad?" ":pad.substring(1)); if (text!="-"){ var d=DOpus; if (d.Version.AtLeast("11.13.1")) d.Output(pad+text,((lvl==1||lvl==2)?1:0)); else d.Output(pad+text);} ind=(ind!==undefined?ind:0);XLog.I+=ind;if(XLog.I<0)throw new Error("XLog indent went sub-zero."); } /////////////////////////////////////////////////////////////////////////////// //The real thing: /////////////////////////////////////////////////////////////////////////////// function Log_PROD_RENAME_ME(text, lvl, ind){ //XLog v0.42 (non-casesensitive options) var u,lvs={o:0,x:1,e:2,w:3,i:4,n:5,t:6,d:7,a:8},i=["","X","E","W","I","","","",""]; if (typeof XLog==(u="undefined")){var v=DOpus.Vars; if (v.Exists("XLog") && typeof XLogForce==u) {XLog=v.Get("XLog"); }} if (typeof XLog==u){var c=Script.Config; if(typeof c!="undefined" && typeof c.XLog!=u){ XLog=c.XLog; }} if (typeof XLog==u){XLog="normal";} if(XLog.paused===undefined){ if(XLog===true) var L=5; else if(!isNaN(parseInt(XLog,10))) var L=XLog*1; else var L=lvs[(""+XLog).toLowerCase().substring(0,1)]; XLog={paused:false,I:0,L:L};} lvl=(lvl==undefined?5:lvs[lvl.substring(0,1).toLowerCase()]); if (!(lvl && XLog.L && !XLog.paused && (lvl<=XLog.L))){ return;} var pad = (XLog.I==0?"":new Array(XLog.I+1).join(" ")); if (i[lvl])pad = i[lvl]+(!pad?" ":pad.substring(1)); if (text!="-"){ var d=DOpus; if (d.Version.AtLeast("11.13.1")) d.Output(pad+text,((lvl==1||lvl==2)?1:0)); else d.Output(pad+text);} ind=(ind!==undefined?ind:0);XLog.I+=ind;if(XLog.I<0)throw new Error("XLog indent went sub-zero."); } /////////////////////////////////////////////////////////////////////////////// function OnAboutScript(data){ //v0.1 var cmd = DOpus.Create.Command(); if (!cmd.Commandlist('s').exists("ScriptWizard")){ if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n"+ "Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers "+ "easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window)) cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');} else cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"'); } //MD5 = "39a5df45d261ea7ace6140827fe67360"; DATE = "2016.02.10 - 20:15:20"