Leaderboard
Popular Content
Showing content with the highest reputation on 09/12/2018 in all areas
-
I routinely need to log information for my scripts. In the past, I've usually just created functions in each script to write to a log file. I also use ConsoleWrite in conjunction with SciTE a lot when I'm trying to debug scripts. After using some logging libraries for other languages (namely NLog (C#) and Java (log4j)) I decided to write a logging UDF for AutoIt. I decided to base it loosely upon the log4j and NLog libaries. I say loosely because this one is not nearly as feature rich as either one of those, but I think it still provides a nice logging interface. What can it do? Output types: Console, File, or Both. Additionally, you can configure the logger to output differently based on whether the script is compiled or not. This way you can output to the console (SciTE) while you're writing a script, and output to a log file when you've compile the script. Log levels: While I don't think it's really necessary to have this many log levels, these are the levels in ascending order of severity: Trace Debug Info Warn Error Fatal Log Filtering: The log can be enabled and disabled. There are also minimum and maximum log levels that can be configured to only show a range of log levels (i.e. a minimum level of warn would not log messages for trace, debug, or info). These filter levels can be overridden when logging a message if the need be. Error Stream: Logging can be configured to write to the stderr (i.e. ConsoleWriteError). When enabled, any log messages at the error level and above will be written to the error stream. Message Format Macros: The logging message format can be customized to your liking using the following macros: ${date} = Long date (i.e. MM/DD/YYYY HH:MM:SS) ${host} = Hostname of local machine ${level} = The current log level ${message} = The log message ${newline} = Insert a newline ${shortdate} = Short date (i.e. MM/DD/YYYY) Available Functions: Configuration Functions _log4a_SetCompiledOutput - Sets the logging output type for the compiled version of the script (Default: $LOG4A_OUTPUT_FILE) _log4a_SetEnable - Enables or disables logging messages (Default: Disabled) _log4a_SetErrorStream - Enables or disables logging of the standard error stream (Default: Enabled) _log4a_SetFormat - Configures the format of logging messages (Default: "${date} ${level} ${message}") _log4a_SetLogFile - Sets the path of the log file (Default: "<ScriptFullPath>.log") _log4a_SetMaxLevel - Configures the maximum log level to process messages (Default: $LOG4A_LEVEL_FATAL) _log4a_SetMinLevel - Configures the minimum log level to process messages (Default: $LOG4A_LEVEL_TRACE) _log4a_SetOutput - Sets the logging output type for the non-compiled version of the script (Default: $LOG4A_OUTPUT_CONSOLE) Logging Functions _log4a_Debug - Logs a message at the debug level _log4a_Error - Logs a message at the error level _log4a_Fatal - Logs a message at the fatal level _log4a_Info - Logs a message at the info level _log4a_Message - Logs a message to the configured outputs _log4a_Trace - Logs a message at the trace level _log4a_Warn - Logs a message at the warn level See the source file for full documentation of available functions. A quick example script: #include "log4a.au3" ; Enable logging and don't write to stderr _log4a_SetEnable() _log4a_SetErrorStream(False) log_messages() ; Write to stderr, set min level to warn, customize message format _log4a_SetErrorStream() _log4a_SetMinLevel($LOG4A_LEVEL_INFO) If @compiled Then _log4a_SetMinLevel($LOG4A_LEVEL_WARN) ; Change the min level if the script is compiled _log4a_SetFormat("${shortdate} | ${host} | ${level} | ${message}") log_messages() ; Disable logging (except for those that override) _log4a_SetEnable(False) log_messages() Func log_messages() _log4a_Trace("A TRACE message", True) ; overrides filters _log4a_Debug("A DEBUG message") _log4a_Info("A INFO message") _log4a_Warn("A WARN message") _log4a_Error("A ERROR message", True) ; overrides filters _log4a_Fatal("A FATAL message") EndFunc Without further adieu, the UDF: log4a.au31 point
-
Delete a registry key if present
Earthshine reacted to careca for a topic
Ok i'll bite, what cant you do?1 point -
Bug? Using empty [ ] declares a Map does't work
iamtheky reacted to JLogan3o13 for a topic
@zdx we are very happy you like @iamtheky's solution, but please don't use the Report button to say thank you.1 point -
A Non-Strict JSON UDF (JSMN)
argumentum reacted to TheXman for a topic
I have found a couple of small issues with the Json_Dump() logic. One issue is related to comparing different data types. The other issue is probably just an oversight. If you run the following example with the latest version of the json UDF, you will get the following console output: #include "json.original.au3" ; <== Modify this line to point to your copy of json.udf ;~ #include "json.modified.au3" ; <== Modify this line to point to your copy of json.udf example() Func example() #cs - PrettyPrint of JSON const below { "null_item": null, "zero_primitive_item": 0, "false_item": false, "true_item": true, "string_item": "This is a string", "array_item": [0,1,2] } #ce Const $JSON_STRING = '{"null_item": null, "zero_primitive_item": 0,"false_item": false,"true_item": true,"string_item": "This is a string","array_item": [0,1,2]}' Json_Dump($JSON_STRING) EndFunc +-> .null_item = +-> .true_item =True +-> .string_item =This is a string +=> .array_item[1]=>1 +=> .array_item[2]=>2 As you can see, items that have a primitive value of 0 or false, do not get written out at all. This was because of comparing different data types. Also notice that values that are null do not display "null", they simply display no value. Since it is a dump, I would assume that you would want to see all values. I have made changes to 5 lines of code in the UDF. When run with my modifications, you get the following output. All lines get displayed with their correct literal values. +-> .null_item =null +-> .zero_primative_item =0 +-> .false_item =false +-> .true_item =true +-> .string_item =This is a string +=> .array_item[0]=>0 +=> .array_item[1]=>1 +=> .array_item[2]=>2 I tried to leave the existing code as close to original as possible. In other words, instead of rewriting the functions, I made the smallest modifications possible in order to get the correct result. I have attached the original and the modified versions of the UDF so that you can easily do a DIFF to see the changes. Each of the modified lines is also denoted by a comment that says ";XC - Changed line" to make them easy to FIND. I just notice that I did make a few more changes to the UDF. I added an extra function, "Json_ObjGetItems(ByRef $Object)". Because I use very strict directives, I made sure that all variables were declared before being used so I would stop getting warnings during compilation. Hopefully my modifications pass muster and can be added to the UDF. Json.modified.au3 Json.original.au31 point -
nodejs, html and ajax - uploading a file - [solved]
Xandy reacted to kaotkbliss for a topic
update, got a fix from my manager. I was close when I tried to use the first ajax call (the top script) I just needed to change data : $("#form8125").serialize(), to data: new FormData($('#lithoform')[0]), contentType: false, and processData: false so close at one point.1 point -
Extended Message Box - New Version: 16 Feb 24
CaptainGadget reacted to Melba23 for a topic
[NEW VERSION] 2 Aug 18 Added: When specifying the icon to use, if the $vIcon parameter is set to the name of an ico or exe file, the main icon within will be displayed, but if a trailing "|" followed by the icon index is added to the name, that icon from within the file is used. New UDF and examples in the first post. M231 point -
How to click on a javascript link/button?
Moonscarlet reacted to corgano for a topic
In many cases _IEAction "click" does not work with javascript-related buttons. I found a way to create a mouseevent and send it to the button to trigger the javascript linked here, which might work when IE's .click() does not.1 point -
In my testing, I found I can go to this size: Global $u[16777216] I simply changed each digit starting from the highest to 5 and worked up or down depending on the result. If you make the number 16777217, you will get a error.1 point