PSGI 日志记录 (Perl)

发布于 2024-12-27 18:28:30 字数 119 浏览 4 评论 0原文

尽管文档相当匮乏且不明确,而且针对初学者的有效操作指南也很少,但我已经开始喜欢 PSGI,并且目前正在我的一个应用程序中使用它。我想知道如何管理跨多节点应用程序的日志记录?关于 PSGI 日志记录,什么被认为是“最佳实践”?

Despite rather scant and unclear documentation and an effective How-To for beginners, I have grown to like PSGI and am currently using it in one of my applications. What I would like to know is how do I manage logging across a multi-node application? What is considered "best practice" regarding logging in PSGI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2025-01-03 18:28:30

我建议使用 Plack::Middleware::AccessLog 进行日志记录访问和 Plack::Middleware::LogDispatch 用于自定义日志记录。
它们又都使用流行的 Log::Dispatch 模块。

LogDispatch Middleware 文档当前不向您展示如何使用
设置后的日志记录对象。下面是一个示例:

my $app = sub {
    my $env = shift;
    $env->{'psgix.logger'}->({ level => "debug", message => "This is debug" });
    return [ 200, [], [] ];
};

要解决多节点问题,您可以使用 Log::Dispatch: :Syslog 会将日志发送到 rsyslog ,而 rsyslog 又可以将日志数据传递给另一个系统日志 服务器。这样,所有节点都可以记录到单个中央日志服务器。

凭借 Log::Dispatch 的灵活性,您还可以选择记录日志
如果您愿意,可以在本地和远程进行冗余。日志发送到
中央服务器可以被认为是主要的,并且日志记录已完成
如果中央日志服务器处于本地状态,则可以考虑在本地进行备份
下来一点。

使用中央日志服务器有几个优点:

  1. 您可以在一处“grep”整个集群中的日志。
  2. 使用一组日志文件,日志轮换和分析会更简单。
  3. 您可以更好地准备扩展和缩小集群,因为您可以关闭节点,而不必担心丢失日志记录,或者保持服务器打开,以便可以触发夜间 cron 作业来处理日志。

我目前以这种方式使用 Log::Dispach 和 Rsyslog 来自己管理多节点集群。

I recommend using Plack::Middleware::AccessLog for logging accessing and Plack::Middleware::LogDispatch for custom logging.
They both in turn use the popular Log::Dispatch module.

The LogDispatch Middleware docs do not currently show you to how to use
the logging object once it is set up. Here's an example:

my $app = sub {
    my $env = shift;
    $env->{'psgix.logger'}->({ level => "debug", message => "This is debug" });
    return [ 200, [], [] ];
};

To address the multi-node concern, you could then use Log::Dispatch::Syslog which would send logging to rsyslog which could in turn to pass the log data on to another rsyslog server. In this way, all the nodes can log to a single central logging server.

With the flexibility of Log::Dispatch, you also have the option to log
both locally and remotely for redundancy if you like. The logs sent to
the central server could be considered primary, and the logging done
locally could be considered backup in case the central log server is
down for a bit.

Using a central log server has several advantages:

  1. You can 'grep' your logs across the entire cluster in one place.
  2. Log rotation and analysis is simpler with one set of log files.
  3. You are better prepared to scale your cluster up and down, as you can shut a node off without worrying about losing the logging, or keeping the server on just so an overnight cron job can fire to process the logs.

I currently using Log::Dispach and Rsyslog together in this way to manage a multi-node cluster myself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文