Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
98 27 33 35

Set Python API logs programmatically.

Is there a way to set through code the location where logs occur when requests are made to the Python API?


Thanks in advance for any help you can provide.

eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
4.3k 2 4 5

Hi,

To simplify this, you can use set_log_path() function:

ek.set_log_path("c:\Temp\eikon")

You'll find logs in this directory.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you Pierre. This approach is different than the one Alex suggested, regardless, it didn't produce the same output. I created a dummy folder to test this one (on c:\desktop\dummy_logs) and the contents were empty after I ran a test.

The version Alex did allocated a .txt file with the logs. So I'm not quite sure what went wrong with your approach. Did I do something wrong? Should I used a similar path?

I noticed this post uses this in combination with ek.set_log_level. @Alex Putkov. appears there too btw.

What I'm not sure of is the integer he plugs in to get a different type of log. According to the guide, there are only 8 options available through the logger. I plugged in 2 different integers as input, 1 and 10. The only virtual difference was that one of the files had a line that was for TRACE.

Why is that? I would like to know. Btw, that option in that post works great as well.

@aquilesjlp300

The logging library defines 8 names for logging levels, which actually represent 6 different logging levels (2 of the 6 logging levels have more than one name: CRITICAL and FATAL are synonymous and represent the same logging level with numeric value of 50, and WARN and WARNING both refer to the logging level with numeric value of 30). In addition to the levels defined in the logging library one can also use custom levels defined in one's code. Eikon Data APIs library defines such custom level with the name "TRACE" and the numeric value of 5.
When a logging method is called on a logger, the logger compares its own level with the level associated with the method call. If the logger’s level is higher than the method call’s, no logging message is actually generated. This is the basic mechanism controlling the verbosity of logging output.
When you set the logging level for pyeikon logger to 10, the logger will output messages with severity of DEBUG (numeric logging level value of 10) and higher. When you set the logging level for pyeikon logger to 1, it will output messages with severity of 1 and higher, which will include messages with severity level of TRACE (numeric logging level value of 5).

@Alex Putkov.thank you so much again for the explanation!

Upvote
39.4k 77 11 27

Eikon Data APIs library for Python uses standard Python library named "logging" to create the log. You can get the logger created by Eikon Data APIs library for Python with

import logging
logger = logging.getLogger('pyeikon')

And then you can add a FileHandler to pyeikon logger to provide output to a file, e.g.

lh = logging.FileHandler('C:\Temp\pyeikon.log')
logger.addHandler(lh) 

I may be wrong, but it sounds like you're not very familiar with the logging library or how the logs are usually created in Python. If this is the case, I suggest you go through some tutorials, of which there's an abundance on the Internet, to learn about the logging library and how to configure the output for the logs produced by Python libraries.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi Alex, thanks a lot! And yes, you guessed right about my knowledge gap for the whole subject of logging folders, but your advice was super useful!


For any code that I produce that imports eikon I'll have to do this, hopefully this will solve the issue I'm facing in which some folder logs are being created in undesirable places. I'll let you know in the upcoming days how it went.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.