Logger Library For Pinescript (Logging and Debugging)

CyberMensch Premium Mis à jour   
Library "LoggerLib"

This is a logging library for Pinescript. It is aimed to help developers testing and debugging scripts with a simple to use logger function.
Pinescript lacks a native logging implementation. This library would be helpful to mitigate this insufficiency.
This library uses table to print outputs into its view. It is simple, customizable and robust.
You can start using it's .log() method just like any other logging method in other languages.


-- Recommended: Please Read The Documentation From Source Code Below. It Is Much More Readable There And Will Be Updated Along With Newer Versions. --

Importing the Library

import paragjyoti2012/LoggerLib/<version_no> as Logger

.init() : Initializes the library and returns the logger pointer. (Later will be used as a function parameter)

.initTable: Initializes the Table View for the Logger and returns the table id. (Later will be used as a function parameter)

logger: The logger pointer got from .init()
max_rows_count: Number of Rows to display in the Logger Table (default is 10)
offset: The offset value for the rows (Used for scrolling the view)
position: Position of the Table View
Values could be:
(default is left)

size: Font Size of content
Values could be:
(default is small)
hide_date: Whether to hide the Date/Time column in the Logger (default is false)

returns: Table

example usage of .initTable()

import paragjyoti2012/LoggerLib/1 as Logger

var logger=Logger.init()
var logTable=Logger.initTable(logger, max_rows_count=20, offset=0, position="top-right")


.log() : Logging Method
params: (string message, |string| logger, table table_id, string type="message")

logger: pass the logger pointer from .init()
table_id: pass the table pointer from .initTable()
message: The message to log
type: Type of the log message
Values could be:
(default is message)

returns: void

Full Boilerplate For Using In Indicator

P.S: Change the | (pipe) character into square brackets while using in script (or copy it from the source code instead),"Offset",minval=0)
size=input.string("small","Font Size",options=|"normal","small","large"|),"No Of Rows")
hide_date=input.bool(false,"Hide Time")

import paragjyoti2012/LoggerLib/1 as Logger

var logger=Logger.init()
var logTable=Logger.initTable(logger,rows,offset,position,size,hide_date)

rsi=ta. rsi (close,14)
|macd,signal,hist|=ta. macd (close,12,26,9)

Logger.log("Dropped Below 34000",logger,logTable,"warning")
Logger.log("Dropped Below 35000",logger,logTable)
Logger.log("Crossed 38000",logger,logTable,"info")
if(ta.crossunder( rsi ,20))
Logger.log("RSI Below 20",logger,logTable,"error")
if(ta.crossover( macd ,signal))
Logger.log("Macd Crossed Over Signal",logger,logTable)
if(ta.crossover( rsi ,80))
Logger.log("RSI Above 80",logger,logTable,"success")

// For Scrolling the Table View

There is a subtle way of achieving nice scrolling behaviour for the Table view. Open the input properties panel for the table/indicator. Focus on the input field for "Offset", once it's focused, you could use your mouse scroll wheel to increment/decrement the offset values; It will smoothly scroll the Logger Table Rows as well.

For any assistance using this library or reporting issues, please write in the comment section below.
I will try my best to guide you and update the library. Thanks :)
Notes de version: v2
Bug Fixes and improvements.
Notes de version: v3



// Added Sticky Logs
// ---------------------------------
// Some logs could be sticked at the bottom of the logs. This type of of logs will be updated without adding more to the list of logs.
// These kind of logs will be helpful to log at the last bar or logs that needs constant attention.
// Maximum recommended rows is 5. Default is set to 0, so it won't show sticky logs without explicitly setting it.
// To log a sticky log, you need to pass the stickPosition parameter (ranging from 1 to 5) in the .log() method.
Notes de version: v4
Bug Fixes
Notes de version: v5
Bibliothèque Pine

Dans le véritable esprit de TradingView, l'auteur a publié ce code Pine en tant que bibliothèque open-source afin que d'autres programmeurs Pine de notre communauté puissent le réutiliser. Bravo à l'auteur ! Vous pouvez utiliser cette bibliothèque à titre privé ou dans d'autres publications open-source, mais la réutilisation de ce code dans une publication est régie par notre Règlement.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser cette bibliothèque?

Copiez le texte dans le presse-papiers et collez-le dans votre script.