class bioMessage: examples of use of each function

This webpage is for programmers who need examples of use of the functions of the class. The examples are designed to illustrate the syntax. They do not correspond to any meaningful model. For examples of models, visit biogeme.epfl.ch.

In [1]:
import datetime
print(datetime.datetime.now())
2019-12-29 21:17:35.541399
In [2]:
import biogeme.version as ver
print(ver.getText())
biogeme 3.2.5 [2019-12-29]
Version entirely written in Python
Home page: http://biogeme.epfl.ch
Submit questions to https://groups.google.com/d/forum/biogeme
Michel Bierlaire, Transport and Mobility Laboratory, Ecole Polytechnique Fédérale de Lausanne (EPFL)

In [3]:
import biogeme.messaging as msg
In [4]:
logger = msg.bioMessage()

We consider 5 levels of reporting:

       - 0: no output (silent, default for screen)
       - 1: warnings only
       - 2: only warnings and general information
       - 3: more verbose (default for file)
       - 4: debug messages

By default, the logger is silent on the screen. No message is displayed.

In [5]:
logger.addMessage("A test",1)

Here we ask to display all messages of level 3 or lower.

In [6]:
logger.setScreenLevel(3)

The following statement applies to both file and screen

In [7]:
logger.setDetailed()

Writing a message of a given level

In [8]:
logger.addMessage("A test",1)
[21:17:35] < Warning >   A test

The following statements are easier to use.

In [9]:
logger.general("A general message")
[21:17:35] < General >   A general message
In [10]:
logger.warning("A warning message")
[21:17:35] < Warning >   A warning message
In [11]:
logger.detailed("A detailed message")
[21:17:35] < Detailed >  A detailed message
In [12]:
logger.debug("A debug message")

A log file can be created

In [13]:
theFile = logger.createLog(fileLevel=4,fileName="_test")
[21:17:35] < General >   Log file created: _test.log
In [14]:
with open(theFile) as f:
    print(f.read())
*** File created 2019-12-29 21:17:35.606777 ***
*** Log file from biogeme 3.2.5 [2019-12-29]
[21:17:35] < Warning >   A test
[21:17:35] < Warning >   A test
[21:17:35] < General >   A general message
[21:17:35] < Warning >   A warning message
[21:17:35] < Detailed >  A detailed message
[21:17:35] < Debug >     A debug message
[21:17:35] < General >   Log file created: _test.log

In [ ]: