◼ Overview A dual logging library for developers. Tradingview lacks logging capability. This library provides logging while developing your scripts and is to be used by developers when developing and debugging their scripts. Using this library would potentially slow down you scripts. Hence, use this for debugging only. Once your code is as you would like it to be, remove the logging code.
◼︎ Usage (Console): Console = A sleek single cell logging with a limit of 4096 characters. When you dont need a large logging capability.
◼︎ Fields (with default settings) ▶︎ IsConsole = True Log will act as Console if true, otherwise it will act as Logx
▶︎ ShowHeader = True (Log only) Will show a header at top or bottom of logx. ▶︎ HeaderAtTop = True (Log only) Will show the header at the top, or bottom if false, if ShowHeader is true. ▶︎ ShowStatusBar = True Will show a status bar at the bottom ▶︎ StatusBarAtBottom = True Will show the status bar at the bottom, or top if false, if ShowHeader is true. ▶︎ ShowMetaStatus = True Will show the meta info within status bar (Current Bar, characters left in console, Paging On Every Bar, Console dumped data etc)
▶︎ ShowBarIndex = True Logx will show column for Bar Index when the message was logged. Console will add Bar index at the front of logged messages ▶︎ ShowDateTime = True Logx will show column for Date/Time passed with the logged message logged. Console will add Date/Time at the front of logged messages ▶︎ ShowLogLevels = True Logx will show column for Log levels corresponding to error codes. Console will log levels in the status bar ▶︎ ReplaceWithErrorCodes = True (Log only) Logx will show error codes instead of log levels, if ShowLogLevels is switched on ▶︎ RestrictLevelsToKey7 = True Log levels will be restricted to Ley 7 codes - TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL, FATAL ▶︎ ShowQ1 = True (Log only) Show the column for Q1 ▶︎ ShowQ2 = True (Log only) Show the column for Q2 ▶︎ ShowQ3 = True (Log only) Show the column for Q3 ▶︎ ShowQ4 = True (Log only) Show the column for Q4 ▶︎ ShowQ5 = True (Log only) Show the column for Q5 ▶︎ ShowQ6 = True (Log only) Show the column for Q6
▶︎ ColorText = True Log/Console will color text as per error codes ▶︎ HighlightText = True Log/Console will highlight text (like denoting) as per error codes
▶︎ AutoMerge = True (Log only) Merge the queues towards the right if there is no data in those queues. ▶︎ PageOnEveryBar = True Clear data from previous bars on each new bar, in conjuction with PageHistory setting. ▶︎ MoveLogUp = True Move log in up direction. Setting to false will push logs down. ▶︎ MarkNewBar = True On each change of bar, add a marker to show the bar has changed ▶︎ PrefixLogLevel = True (Console only) Prefix all messages with the log level corresponding to error code.
▶︎ MinWidth = 40 Set the minimum width needed to be seen. Prevents logx/console shrinking below these number of characters. ▶︎ TabSizeQ1 = 0 If set to more than one, the messages on Q1 or Console messages will indent by this size based on error code (Max 4 used) ▶︎ TabSizeQ2 = 0 If set to more than one, the messages on Q2 will indent by this size based on error code (Max 4 used) ▶︎ TabSizeQ3 = 0 If set to more than one, the messages on Q2 will indent by this size based on error code (Max 4 used) ▶︎ TabSizeQ4 = 0 If set to more than one, the messages on Q2 will indent by this size based on error code (Max 4 used) ▶︎ TabSizeQ5 = 0 If set to more than one, the messages on Q2 will indent by this size based on error code (Max 4 used) ▶︎ TabSizeQ6 = 0 If set to more than one, the messages on Q2 will indent by this size based on error code (Max 4 used) ▶︎ PageHistory = 0 Used with PageOnEveryBar. Determines how many historial pages to keep.
▶︎ HeaderQbarIndex = 'Bar#' (Logx only) The header to show for Bar Index ▶︎ HeaderQdateTime = 'Date' (Logx only) The header to show for Date/Time ▶︎ HeaderQerrorCode = 'eCode' (Logx only) The header to show for Error Codes ▶︎ HeaderQlogLevel = 'State' (Logx only) The header to show for Log Level ▶︎ HeaderQ1 = 'h.Q1' (Logx only) The header to show for Q1 ▶︎ HeaderQ2 = 'h.Q2' (Logx only) The header to show for Q2 ▶︎ HeaderQ3 = 'h.Q3' (Logx only) The header to show for Q3 ▶︎ HeaderQ4 = 'h.Q4' (Logx only) The header to show for Q4 ▶︎ HeaderQ5 = 'h.Q5' (Logx only) The header to show for Q5 ▶︎ HeaderQ6 = 'h.Q6' (Logx only) The header to show for Q6 ▶︎ Status = '' Set the status to this text.
▶︎ HeaderColor Set the color for the header ▶︎ HeaderColorBG Set the background color for the header ▶︎ StatusColor Set the color for the status bar ▶︎ StatusColorBG Set the background color for the status bar ▶︎ TextColor Set the color for the text used without error code or code 0. ▶︎ TextColorBG Set the background color for the text used without error code or code 0. ▶︎ FrameColor Set the color for the frame around Logx/Console ▶︎ FrameSize = 1 Set the size of the frame around Logx/Console ▶︎ CellBorderSize = 0 Set the size of the border around cells. ▶︎ CellBorderColor Set the color for the border around cells within Logx/Console ▶︎ SeparatorColor = gray Set the color of separate in between Console/Logx Attachment
◼︎ Methods (summary) ● init ▶︎ Initialise the log ● log ▶︎ Log the messages. Use method show to display the messages ● page ▶︎ Clear messages from previous bar while logging messages on this bar. ● show ▶︎ Shows a table displaying the logged messages ● clear ▶︎ Clears the log of all messages ● resize ▶︎ Resizes the log. If size is for reduction then oldest messages are lost first. ● turnPage ▶︎ When called, all messages marked with previous page, or from start are cleared ● dateTimeFormat ▶︎ Sets the date time format to be used when displaying date/time info.
● resetTextColor ▶︎ Reset Text Color to library default ● resetTextBGcolor ▶︎ Reset Text BG Color to library default ● resetHeaderColor ▶︎ Reset Header Color to library default ● resetHeaderBGcolor ▶︎ Reset Header BG Color to library default ● resetStatusColor ▶︎ Reset Status Color to library default ● resetStatusBGcolor ▶︎ Reset Status BG Color to library default
● setColors ▶︎ Sets the colors to be used for corresponding error codes ● setColorsBG ▶︎ Sets the background colors to be used for corresponding error codes. If not match of error code, then text color used. ● setColorsHC ▶︎ Sets the highlight colors to be used for corresponding error codes.If not match of error code, then text bg color used. ● resetColors ▶︎ Reset the colors to library default (Total 36, not including error code 0) ● resetColorsBG ▶︎ Reset the background colors to library default ● resetColorsHC ▶︎ Reset the highlight colors to library default
● setLevelNames ▶︎ Set the log level names to be used for corresponding error codes. If not match of error code, then empty string used. ● resetLevelNames ▶︎ Reset the log level names to library default. (Total 36) 1=TRACE, 2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=CRITICAL, 7=FATAL
● attach ▶︎ Attaches a console to an existing Logx, allowing to have dual logging system independent of each other ● detach ▶︎ Detaches an already attached console from Logx
method clear(this) Clears all the queue, including bar_index and time queues, of existing messages Namespace types: log Parameters: this (log)
method resize(this, rows) Resizes the message queues. If size is decreased then removes the oldest messages Namespace types: log Parameters: this (log) rows (int): The new size needed for the queues. Default value is 40.
method dateTimeFormat(this, format) Re/set the date time format used for displaying date and time. Default resets to dd.MMM.yy HH:mm Namespace types: log Parameters: this (log) format (string)
method resetTextColor(this) Resets the text color of the log to library default. Namespace types: log Parameters: this (log)
method resetTextColorBG(this) Resets the background color of the log to library default. Namespace types: log Parameters: this (log)
method resetHeaderColor(this) Resets the color used for Headers, to library default. Namespace types: log Parameters: this (log)
method resetHeaderColorBG(this) Resets the background color used for Headers, to library default. Namespace types: log Parameters: this (log)
method resetStatusColor(this) Resets the text color of the status row, to library default. Namespace types: log Parameters: this (log)
method resetStatusColorBG(this) Resets the background color of the status row, to library default. Namespace types: log Parameters: this (log)
method resetFrameColor(this) Resets the color used for the frame around the log table, to library default. Namespace types: log Parameters: this (log)
method resetColorsHC(this) Resets the color used for the highlighting when Highlight Text option is used, to library default Namespace types: log Parameters: this (log)
method resetColorsBG(this) Resets the background color used for setting the background color, when the Color Text option is used, to library default Namespace types: log Parameters: this (log)
method resetColors(this) Resets the color used for respective error codes, when the Color Text option is used, to library default Namespace types: log Parameters: this (log)
method setColors(this, c) Sets the colors corresponding to error codes Index 0 of input array c is color is reserved for future use. Index 1 of input array c is color for debug code 1. Index 2 of input array c is color for debug code 2. There are 2 modes of coloring 1 . Using the Foreground color 2 . Using the Foreground color as background color and a white/black/gray color as foreground color This is denoting or highlighting. Which effectively puts the foreground color as background color Namespace types: log Parameters: this (log) c (color[]): Array of colors to be used for corresponding error codes. If the corresponding code is not found, then text color is used
method setColorsHC(this, c) Sets the highlight colors corresponding to error codes Index 0 of input array c is color is reserved for future use. Index 1 of input array c is color for debug code 1. Index 2 of input array c is color for debug code 2. There are 2 modes of coloring 1 . Using the Foreground color 2 . Using the Foreground color as background color and a white/black/gray color as foreground color This is denoting or highlighting. Which effectively puts the foreground color as background color Namespace types: log Parameters: this (log) c (color[]): Array of highlight colors to be used for corresponding error codes. If the corresponding code is not found, then text color BG is used
method setColorsBG(this, c) Sets the highlight colors corresponding to debug codes Index 0 of input array c is color is reserved for future use. Index 1 of input array c is color for debug code 1. Index 2 of input array c is color for debug code 2. There are 2 modes of coloring 1 . Using the Foreground color 2 . Using the Foreground color as background color and a white/black/gray color as foreground color This is denoting or highlighting. Which effectively puts the foreground color as background color Namespace types: log Parameters: this (log) c (color[]): Array of background colors to be used for corresponding error codes. If the corresponding code is not found, then text color BG is used
method resetLevelNames(this, prefix, suffix) Resets the log level names used for corresponding error codes With prefix/suffix, the default Level name will be like => prefix + Code + suffix Namespace types: log Parameters: this (log) prefix (string): Prefix to use when resetting level names suffix (string): Suffix to use when resetting level names
method setLevelNames(this, names) Resets the log level names used for corresponding error codes Index 0 of input array names is reserved for future use. Index 1 of input array names is name used for error code 1. Index 2 of input array names is name used for error code 2. Namespace types: log Parameters: this (log) names (string[]): Array of log level names be used for corresponding error codes. If the corresponding code is not found, then an empty string is used
method init(this, rows, isConsole) Sets up data for logging. It consists of 6 separate message queues, and 3 additional queues for bar index, time and log level/error code. Do not directly alter the contents, as library could break. Namespace types: log Parameters: this (log) rows (int): Log size, excluding the header/status. Default value is 50. isConsole (bool): Whether to init the log as console or logx. True= as console, False = as Logx. Default is true, hence init as console.
method log(this, ec, m1, m2, m3, m4, m5, m6, tv, log) Logs messages to the queues , including, time/date, bar_index, and error code Namespace types: log Parameters: this (log) ec (int): Error/Code to be assigned. m1 (string): Message needed to be logged to Q1, or for console. m2 (string): Message needed to be logged to Q2. Not used/ignored when in console mode m3 (string): Message needed to be logged to Q3. Not used/ignored when in console mode m4 (string): Message needed to be logged to Q4. Not used/ignored when in console mode m5 (string): Message needed to be logged to Q5. Not used/ignored when in console mode m6 (string): Message needed to be logged to Q6. Not used/ignored when in console mode tv (int): Time to be used. Default value is time, which logs the start time of bar. log (bool): Whether to log the message or not. Default is true.
method page(this, ec, m1, m2, m3, m4, m5, m6, tv, page) Logs messages to the queues , including, time/date, bar_index, and error code. All messages from previous bars are cleared Namespace types: log Parameters: this (log) ec (int): Error/Code to be assigned. m1 (string): Message needed to be logged to Q1, or for console. m2 (string): Message needed to be logged to Q2. Not used/ignored when in console mode m3 (string): Message needed to be logged to Q3. Not used/ignored when in console mode m4 (string): Message needed to be logged to Q4. Not used/ignored when in console mode m5 (string): Message needed to be logged to Q5. Not used/ignored when in console mode m6 (string): Message needed to be logged to Q6. Not used/ignored when in console mode tv (int): Time to be used. Default value is time, which logs the start time of bar. page (bool): Whether to log the message or not. Default is true.
method turnPage(this, turn) Set the messages to be on a new page, clearing messages from previous page. This is not dependent on PageHisotry option, as this method simply just clears all the messages, like turning old pages to a new page. Namespace types: log Parameters: this (log) turn (bool)
method show(this, position, hhalign, hvalign, hsize, thalign, tvalign, tsize, show, attach) Display Message Q, Index Q, Time Q, and Log Levels All options for postion/alignment accept TV values, such as position.bottom_right, text.align_left, size.auto etc. Namespace types: log Parameters: this (log) position (string): Position of the table used for displaying the messages. Default is Bottom Right. hhalign (string): Horizontal alignment of Header columns hvalign (string): Vertical alignment of Header columns hsize (string): Size of Header text Options thalign (string): Horizontal alignment of all messages tvalign (string): Vertical alignment of all messages tsize (string): Size of text across the table show (bool): Whether to display the logs or not. Default is true. attach (log): Console that has been attached via attach method. If na then console will not be shown
method attach(this, attach, position) Attaches a console to Logx, or moves already attached console around Logx All options for position/alignment accept TV values, such as position.bottom_right, text.align_left, size.auto etc. Namespace types: log Parameters: this (log) attach (log): Console object that has been previously attached. position (string): Position of Console in relation to Logx. Can be Top, Right, Bottom, Left. Default is Bottom. If unknown specified then defaults to bottom.
method detach(this, attach) Detaches the attached console from Logx. All options for position/alignment accept TV values, such as position.bottom_right, text.align_left, size.auto etc. Namespace types: log Parameters: this (log) attach (log): Console object that has been previously attached.
リリースノート
◼︎ Usage (Logx) (corrected): Logx = Multiple columns logging with a limit of 4096 characters each message. When you need to log large number of messages.
◼︎ Methods Changed (summary) ● log ▶︎ Fixed some cases where string would get too large and throw an error. Added ability to specify one of the two fonts to use, as well as tooltip for each row
◼︎ Fields Added (with default settings) ▶︎ HeaderTooltip = 'Header' Tooltip to display when mouse hovers over header (Logx Only) ▶︎ StatusTooltip = 'Status' Tooltip to display when mouse hovers over status bar ▶︎ MetaStatusTooltip = 'Meta Info' Tooltip to display when mouse hovers over meta info section of status bar
◼︎ Methods Added (summary) ● alog ▶︎ Log messages asynchronously, one queue at a time
● setColor ▶︎ Set the color to be used for corresponding error code. Has an overloaded function to supply 3 colors at same time. If supplied a code not in current array, color array will expand. ● setColorBG ▶︎ Set the background colors to be used for corresponding error code. If supplied a code not in current array, color array will expand. ● setColorHC ▶︎ Set the highlight colors to be used for corresponding error code. If supplied a code not in current array, color array will expand. ● setLevelName ▶︎ Set the log level name to be used for corresponding error code. If supplied a code not in current array, log level name array will expand.
● getColor ▶︎ Get the color being used for corresponding error code. If supplied a code not in current array, will return na ● getColorBG ▶︎ Get the background color being used for corresponding error codes. If supplied a code not in current array, will return na. ● getColorHC ▶︎ Get the highlight color being used for corresponding error codes. If supplied a code not in current array, will return na. ● getLevelName ▶︎ Get the log level name being used for corresponding error codes. If supplied a code not in current array, will return na.
● setFontHeader ▶︎ Set font to be used for Header. Use this to either set or reset to default. Accepts the TV font values. ● setFontStatus ▶︎ Set font to be used for Status. Use this to either set or reset to default. Accepts the TV font values. ● setFontMetaStatus ▶︎ Set font to be used for meta info in Status Bar. Use this to either set or reset to default. Accepts the TV font values.
リリースノート
v3
Demonstration of the library usage via this script => When you see how it works, then you can look up the library code for functions/methods or just simply call one of the 4 documentation functions listed below.
Changes: - Better error checking. Should not see anymore errors on usage now. I am using this for my debugging my other code developments and that has helped to thrash out issues from v1 and v2. - Improvements to async logging - Addition of individual coloring of cells when logging. - Ability to revert logged messages (undoing messages) - New overloaded functions for letting all types of calls to log/alog/page/logX/undo/undoQ/undoX - Massive improvements to documentation.
Known Issues/Limitation: - When using this library your script will compile for lot longer and may slow down as well. This should be ok, as long as you debug parts of code and move them to a final working version of the script. This library is just for debugging your code. - The library itself is reaching the max compiled code limits on my development version.
Next Update: - I will look to see if I can implement independent queues (logging 6 queues separately, not asynchronously.).
For up to date documentation, import the Library and Call docs(), and hover mouse over docs() to see Docs in Editor!
import GETpacman/logger/3 as logger logger.usage() logger.fields() logger.methods() logger.docs()