Logging
Log everything your algorithm does so that you never miss what it is is upto.
Module
libkloudtrader.logs
Libkloudtrader uses python's very popular and convenient logging module. The levels of logging are same as in the logging module but libkloudtrader.logs changes some basic configs so that the logs' reading experience becomes more easy and user-friendly.
Logging is always encouraged instead of using a print() statement because of the following reasons:
- You can categorize your messages.
- Reading and Viewing becomes better.
- Incident and Event Tracking becomes easier.
- Can actaully find out when an event or signal ocurred which is pretty important for algorithmic trading.
Initializing the logger
Initiating a logger is very simple. Once the logger is initialized you can continue to use it throughout your algorithm.
from libkloudtrader.logs import start_logger
logger = start_logger(__name__)
Examples
Info
To log any kind of information you can use the INFO level of the logger.
logger.info(message)
Paramters | Required/Optional | Description | Type |
---|---|---|---|
message | required | The message you want to log. | str |
Example
from libkloudtrader.logs import start_logger
logger=start_logger(__name__)
logger.info("Hey! Your algorithm found something interesting.")
Tuesday, September 03, 2019 04:23:16 PM INFO: Hey! Your algorithm found something interesting.
Warning
To log any kind of warning you can use the WARNING level of the logger.
logger.warning(message)
Paramters | Required/Optional | Description | Type |
---|---|---|---|
message | required | The message you want to log. | str |
Example
from libkloudtrader.logs import start_logger
logger=start_logger(__name__)
logger.warning("Uh Oh! This isn't the trend we modelled.")
Tuesday, September 03, 2019 04:50:59 PM WARNING: Uh Oh! This isn't the trend we modelled.
Critical
To log any kind of Critical Information you can use the CRITICAL level of the logger.
logger.critical(message)
Paramters | Required/Optional | Description | Type |
---|---|---|---|
message | required | The message you want to log. | str |
Example
from libkloudtrader.logs import start_logger
logger=start_logger(__name__)
logger.critical("This did not go as planned.")
Tuesday, September 03, 2019 05:01:21 PM CRITICAL: This did not go as planned.
Error
To log any kind of error or exception you can use the ERROR level of the logger.
logger.error(message)
Paramters | Required/Optional | Description | Type |
---|---|---|---|
message | required | The message you want to log. | str |
Example
from libkloudtrader.logs import start_logger
logger=start_logger(__name__)
logger.error("Oops! Something broke.")
Tuesday, September 03, 2019 05:02:26 PM ERROR: Oops! Something broke.