MessageLevel in QGIS3
The proper syntax is like below:
# First import Qgis class
from qgis.core import Qgis
...
def something():
# Then you have to use like 'Qgis.MessageLevel' (Qgis.Info as an example)
iface.messageBar().pushMessage(text, level=Qgis.Info)
For more information, please review Communicating with the user and QGIS API Documentation.
You can make a util function like this,
from qgis.core import Qgis as QGis
def showUserMessage(before, text="", level=QGis.Info, duration=3):
''' Show user info/warning/error messages '''
iface.messageBar().popWidget()
iface.messageBar().pushMessage(before, text, level=level, duration=duration)
return
showUserMessage( "Info : ", "Info Sample")
showUserMessage( "Warning :", "Warning Sample",QGis.Warning)
showUserMessage( "Critical : ", "Critical Sample", QGis.Critical)