Mojo::Log的正确使用方法是什么?

What is the correct way to use Mojo::Log?

我想使用 Mojolicious 的 Mojo::Log 工具来登录我的 Mojolicious Web 应用程序。但是,我不确定 proper/correct 的使用方式。

documentation 显示它直接从脚本中使用,但没有说明它是线程安全的还是在控制器之间共享是安全的,或者每个控制器是否应该实例化自己的 Mojo::Log 对象(在那种情况下,它们都指向同一个日志文件是否安全?)。

使用此记录器的正确方法是什么?

Mojolicious 应用程序有一个 Mojo::Log 对象,可由 log attribute, which it uses for logging. Most controllers should be able to share this and its behavior will be set up according to the current mode, log level environment variables, etc. Mojolicious does not use threads itself but an IOLoop which is cooperative multitasking, nothing is actually running at the same time in a process; it uses flocked 写入访问,因此它可以安全地与其他执行相同操作的进程并发,例如在像 Hypnotoad 这样具有多个写入同一日志的工作人员。

# startup or plugin code
$app->log->debug('Debug message');

# controller or helper code
$c->app->log->info('Something happened');