0

I’m using AsyncMachine to model multiple objects interacting asynchronously and in principle, all works as expected, really a cool extension ;-)

However, when I use logging, the millisecond delays which are reported in log entries between processing multiple, asynchronous events are higher than I would expect, so I’m wondering whether this is due to logging output created by a blocking call to e.g. logger.info(). So the timings I’m trying to obtain by looking at log entry timestamps could be distorted by the creation of exactly those logs.

Using https://pypi.org/project/aiologger/ seems like a reasonable way forward, given that aiologger implements non-blocking logging specifically for asyncio.

After a quick look at pytransitions source code I’m wondering however what would happen if pytransitions itself still uses the logging module from the standard library while my code would use the logger offered by aiologger. My guess is that in this case, only the logs created by my code would be non-blocking, so how could I make pytransitions use aiologger as well?

Thanks in advance for any help,

Eradian

Alihossein shahabi
  • 4,034
  • 2
  • 33
  • 53
Eradian
  • 1
  • 2

1 Answers1

0

so how could I make pytransitions use aiologger as well?

As of September 2022 there is no way of making transitions work with aiologger. Due to backward compatibility reasons, transitions uses the %-formatting style for debug messages:

logging.warn("Object %s is initialized with value %d", object.name, object.value)

Theoretically you could override the internal logger instance used by AsyncMachine:

from aiologger import Logger
import transitions.extensions.asyncio as taio

taio._LOGGER = Logger.with_default_handlers(name='transitions.async')
# ...
m = taio.AsyncMachine(states=['A', 'B', 'C'], initial='A')

But this will throw errors during the first logging attempt because of the aforementioned reason:

Invalid LogRecord args type: <class 'str'>. Expected Mapping
aleneum
  • 2,083
  • 12
  • 29