0

I'm trying to configure locust to store my log files into a a logs/ directory. For example:

# example.conf
locustfile = example/locust.py
host = http://www.example.com
users = 10
spawn-rate = 10
logfile = logs/example.log

However, locust will fail if the logs/ directory does not exist. I've tried adding the directory with an init event listener:

@events.init.add_listener
def on_init(**kw):
    if 'logs' not in os.listdir():
        os.mkdir('logs')

But locust fails before it gets to this point. Is there any way around this issue with the current way locust is built?

ahoyt41
  • 17
  • 1
  • 7

1 Answers1

2

Just put your code in the top/module level of your locust file, not inside a function, and it will be executed before everything else.

if 'logs' not in os.listdir():
    os.mkdir('logs')
Cyberwiz
  • 11,027
  • 3
  • 20
  • 40