Enabling Logging in CCS
=======================

The ``log`` driver may be used to easily add debug logging capabilities
to any project. The main benefit of the ``log`` driver is operates
entirely through JTAG which means that no UART peripherals are necessary
to enable the logging functionality. In other words, you do not have
to use up a UART peripheral or modify your project's UART operation
to enable debug logging for your debugging purposes.

Setting up the Logging Functionality
------------------------------------

1. To start, import the desired project into CCS. 
    
    * For this example, Basic BLE project will be used. 

2. Next, add ``${COM_TI_SIMPLELINK_LOWPOWER_F3_SDK_INSTALL_DIR}/source/ti/log/lib/ticlang/m0p/log_cc23x0r5.a`` 
   to the File Search Path, which is found by right clicking the project |rarr| ``Properties`` |rarr|
   ``Build`` |rarr| ``Arm Linker`` |rarr| ``File Search``. Click the add icon to add the path. 
   The properties tab should look like the image below when completed correctly. 
   After adding the file path, click Apply and Close. 

   .. figure:: /debugging/resources/logging_include_path.png

3. Add ``ti_log_Log_ENABLE`` to the Predefined Symbols. This is also found within the properties of the project. 
   Right click the project |rarr| ``properties`` |rarr| ``Build`` |rarr| ``Arm Compiler`` |rarr| ``Predefined Symbols``. 
   Add this with the paper icon with the green plus. The properties tab should look like the image below 
   when completed correctly. After adding the predefined symbol, click Apply and Close.

   .. figure:: /debugging/resources/logging_predefined_symbols.png

Setting up Log Modules
----------------------

1. Open the Basic BLE SysConfig file. The logging module is configured
   through SysConfig. Under ``LOGGING``, is a section for log modules. 
   Here, the log modules will be added.  Once in the Log Modules SysConfig section, click on ``ADD``
   to add a Log Module instance. Name the module ``LogModule_App1``. 
   Within this module, make sure the  ``Enable Module`` 
   check box is checked. Next check the ``Enable Level DEBUG``, ``Enable Level VERBOSE``, and 
   ``Enable Level INFO``. Make set the sink to ``/ti/log/LogSinkBuf`` and 
   ensure ``Logger Sink Instance`` is set to ``CONFIG_ti_log_LogSinkBuf_0``. 
   
   The module will look like the following if the previous steps are followed.

   .. figure:: /debugging/resources/log_module.png
   
2. Within the ``Global Parameters`` section check ``Global Enable Module``, then 
   under the ``Global Log Level Configuration`` subsection, check ``Enable Level DEBUG``, ``Enable Level VERBOSE``,
   and ``Enable Level INFO``

3. Check ``LOG SINKS`` module in SysConfig, and verify the name is properly set:

   .. figure:: /debugging/resources/logsink_settings.png
   
   To test the log function, add the code below into the main function.

    .. code-block:: c
        :linenos:

        Log_printf(LogModule_App1, Log_DEBUG, "Hello world");
   
   Add also the following include:

    .. code-block:: c
        :linenos:

        #include <log/Log.h>   

4. Once this is done, debug and flash the program to the board. 
   While the board is in debug mode, you may open the log
   by going to ``Tools`` |rarr| ``Runtime Object View``.
   After ROV is open, click on ``LogSinkBuf`` within ROV,
   and set the ``LogSinkBuf`` to ``Records``, and 
   then click the continuous refresh button to keep the log 
   constantly updating. It should look like this: 

   .. figure:: /debugging/resources/log_rov.png

.. _Log Example: https://dev.ti.com/tirex/explore/node?node=A__AECWVqZ0C9Gw7.jf0ws88w__com.ti.SIMPLELINK_LOWPOWER_F3_SDK__58mgN04__LATEST

This completes the basic set up for the logging functionality. Additionally, more ``Log_printf`` 
can be added in various locations to indicate different tasks. The debug level may be changed
or outright disabled during debugging depending on which parts of the programs you want to debug
or would like to receive messages for.

For more information on the log function, make sure to reference the  `Log Example`_ for
a drivers-only example that contains the logging functinoality. The readme for the example
also provides valuable insight into how the log driver works and how you can use it in your
custom project.