OPEN-SOURCE SCRIPT

libhs.log.DEMO

Обновлено
Overview
This is a demonstration of dual logging library I have ported from my personal use for public use. Please start bar replay from Bar#4, and progress automatically slowly or manually.You would need to go through 450+ bars to see the full capability.

Logger=A dual logging library for developers. Tradingview lacks logging capability. This library provided 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.


◼︎ Usage (Logx):
Logx = Multiple columns logging with a limit of 4096 characters each message. When you need to log large number of messages.


◼︎ 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
Информация о релизе

◼︎ Usage (Logx) (corrected):
Logx = Multiple columns logging with a limit of 4096 characters each message. When you need to log large number of messages.


◼︎ Usage (Console) (corrected):
Console = A sleek single cell logging with a limit of 4096 characters. When you dont need a large logging capability.


◼︎ 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 of Logger library released.
Demo code updated to reflect the changes in the library and showcase new features

Library 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()
Pine utilities

Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?

Отказ от ответственности