For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Does backtrader suppress logging emitted to stdout by the Python logger internally to Cerebro?



  • I have coded up a strategy that should be utilizing the parent (__main__) logger's level (logging.DEBUG), but I cannot get calls to logging.info() to write to stdout. I'm not new to Python logging, and I've proven to myself that if I instantiate an instance of my strategy, the logging is visible in stdout.

    Is this by design? What was the motivation for bypassing the logging library in this fashion? The examples utilize print internal to the Strategy class implementation, but I think many of us can agree that using print in production is simply a bad idea.


  • administrators

    backtrader doesn't even import the logging module.

    You may have proven whatever you think you have proven, but without showing with which code you have proven the unprovable ...

    Just let us know what have you proven and more importantly how ... you are the one with requirements for production (shall I recall that the platform has costed you nothing?)



  • Hi all,

    I do also see the benefits of using standard python logging capabilities throughout the framework and user code:

    • easy logging redirection (stdout, files, log servers)
    • possible external configuration
    • filtering (by components, by log levels)
    • there are probably others that I can't think about right now

    The question is an effort estimation and someone willing to invest - and I actually do want to try.

    Looking at the backtrader's source code, it seems there are just a few places that directly use 'print' to output to stdout/stderr (excluding samples and tests ).

    Searching 343 files for "print" (case sensitive, whole word)
    
    \\vladnas\work\backtrader\backtrader\brokers\oandabroker.py:
      102:                 print('position for instrument:', p['instrument'])
    
    \\vladnas\work\backtrader\backtrader\btrun\btrun.py:
      148:             print('====================')
      149:             print('== Analyzers')
      150:             print('====================')
      153:                     analyzer.print()
      155:                     print('##########')
      156:                     print(name)
      157:                     print('##########')
      354:                 print('')
      355:                 print('Failed to load module %s:' % modpath, e)
      363:             print('No class %s / module %s' % (str(name), modpath))
      398:                 print('')
      399:                 print('Failed to load module %s:' % modpath, e)
      407:             print('No function %s / module %s' % (str(name), modpath))
      631:                        help=('Automatically print analyzers'))
      635:                        help=('Automatically PRETTY print analyzers'))
    
    \\vladnas\work\backtrader\backtrader\feeds\influxfeed.py:
       69:             print('Failed to establish connection to InfluxDB: %s' % err)
       96:             print('InfluxDB query failed: %s' % err)
    
    \\vladnas\work\backtrader\backtrader\feeds\vcdata.py:
      581:         print('*' * 50, 'DEBUG OnNewTicks')
      583:             print('-' * 40)
      584:             print('tick.SymbolCode', tick.SymbolCode.encode('ascii', 'ignore'))
      586:             print('  tick.Field   : {} ({})'.format(fname, tick.Field))
      587:             print('  tick.FieldEx :', tick.FieldEx)
      591:             print('  tick.Date    :', tdate)
      593:             print('  tick.Index   :', tick.TickIndex)
      594:             print('  tick.Value   :', tick.Value)
      595:             print('  tick.Text    :', tick.Text.encode('ascii', 'ignore'))
    
    
    \\vladnas\work\backtrader\backtrader\stores\ibstore.py:
      329:             print(*args)
    '''
    
    So it seems not a large effort to refactor it to use the standard logging. Of cause this need to be properly designed and discussed.
    
    Would such pull request be accepted by the maintainer(s) ? 
    Or there is some principal position to use just a plain prints ? 
    Or there is another design direction ?
    
    Thanks
    Vlad


  • Sorry, some text got inside the code section, quoting it once again:

    So it seems not a large effort to refactor it to use the standard logging. Of cause this need to be properly designed and discussed.

    Would such pull request be accepted by the maintainer(s) ?
    Or there is some principal position to use just a plain prints ?
    Or there is another design direction ?

    Thanks
    Vlad


  • administrators

    1. The original poster claimed no benefits from logging, the claim was that cerebro was suppressing logging emitted to stdout.

    That claim is 100% false (as stated above logging is not even imported)

    1. https://community.backtrader.com/topic/376/eodevelopment-1-x

    @vladisld said in Does backtrader suppress logging emitted to stdout by the Python logger internally to Cerebro?:

    Looking at the backtrader's source code, it seems there are just a few places that directly use 'print' to output to stdout/stderr (excluding samples and tests ).

    1. Places with print
    • btrun: that's a utility and not part of the core.

    • oandabroker: that's clearly a leftover which shouldn't be there. Given that oandav1 is no longer actual, it doesn't matter.

    • vcdata: only there for very low level debugging purposes. They are even in a method which is not referenced in the code, meant only for future use in re-development if needed.

    • ibstore: only there for very low level debugging purposes. One has to specifically activate the printing.

    • influxfeed: this was an unfortunate pull-request which was accepted. The print statements are guarded by try/except clauses. Never used this and will never use it. It should have been a module in GitHub maintained by the developer.



  • @backtrader said in Does backtrader suppress logging emitted to stdout by the Python logger internally to Cerebro?:

    https://community.backtrader.com/topic/376/eodevelopment-1-x

    Sorry to hear about EOD. Was the development of 2.x started, or am I missing something big ?
    I actually like the platform very much and the fact that it is open source (and not only because of it being free ) is a huge advantage. So I wonder why to stop the development ?


  • administrators

    Because it does everything it was intended to do and a lot more.

    It covers most use cases and has a lot more features than any other (afaik)


Log in to reply
 

});