在 Mac 上读取系统日志输出

发布于 2024-07-09 20:25:51 字数 249 浏览 9 评论 0原文

我有一个为 Linux 编写的程序,我正在尝试在我的 MacOS 10.5 机器上构建并运行它。 该程序构建并运行没有问题,但它对系统日志进行了多次调用。 我知道 syslogd 正在我的 mac 上运行,但是我似乎找不到我的 syslog 调用输出到的位置。

系统日志调用的形式是

syslog (LOG_WARNING, "Log message");

知道在哪里可以找到日志输出吗?

I have a program that was written for linux and I am trying to build and run it on my MacOS 10.5 machine. The program builds and runs without problem, however it makes many calls to syslog. I know that syslogd is running on my mac, however I can't seem to find where my syslog calls are output to.

The syslog calls are of the form

syslog (LOG_WARNING, "Log message");

Any idea where I might find my log output?

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

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

发布评论

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

评论(9

金橙橙 2024-07-16 20:25:51

/var/log/system.log

您可以使用 tail -f /var/log/system.log 轻松监控它。

另请参阅“记录器”(man logger)和“syslog”(man syslog)。

/var/log/system.log

You can monitor it easily using tail -f /var/log/system.log

See also the "logger" (man logger) and "syslog" (man syslog).

十六岁半 2024-07-16 20:25:51

您可能应该使用 Console.app 来查看日志文件。 这是普迪。

在左侧选择您的设备并在右侧过滤消息:

在此处输入图像描述

You should probably use the Console.app to view logfiles. It's purdy.

Select your device on the left and filter messages on the right:

enter image description here

红ご颜醉 2024-07-16 20:25:51

也许有趣的是:Apple 过去使用的是真正的 syslogd,但与此同时,所有这些都已切换到 ASL(Apple 系统日志)。 syslog 命令仍然可用,但它只会访问这一日志。 如果要访问配置的所有日志文件中的 ASL 的所有日志消息,请使用 log 命令。

例如,以下显示了 Safari 在过去两天内生成的所有日志消息(请耐心等待,可能需要一段时间):

log show --predicate 'process == "Safari"' --last 2d

请参阅 man log 了解您可以执行的所有操作、它知道的所有参数以及什么您可以过滤的属性。

Maybe interesting to note: Apple was using a real syslogd in the past but meanwhile all of this has switched to ASL (Apple System Log). The syslog command is still available, but it will only access this one log. If you want to access all log messages of ASL across all log files configured, use the log command.

E.g. the following shows all log messages produced by Safari within the last two days (be patient, can take a while):

log show --predicate 'process == "Safari"' --last 2d

See man log for all the actions you can perform, all the parameters it knows and what attributes you can filter for.

寻梦旅人 2024-07-16 20:25:51

如有疑问,总有 man syslog

您可以在 /var/log/syslog 中找到您的消息; 我的机器开箱即用,仅包含高级消息,因此您可能需要进行设置。

您还可以通过syslog(1)读取消息,或者使用诸如

$ syslog -s -l INFO "Hello, world."

使用严重性 P(“恐慌”)之类的命令创建测试消息,您将立即在控制台上收到令人兴奋的消息。

When in doubt, there's always man syslog.

You can find your messages in /var/log/syslog; my machine is set up out of the box to only include high level messages so you may need to have your settings.

You can also read the messages through syslog(1), or create a test message with a command like

$ syslog -s -l INFO "Hello, world."

use a severity of P ("panic") and you'll get an exciting message on your console immediately.

输什么也不输骨气 2024-07-16 20:25:51

Mac OS X 实现系统日志功能的超集。 所有系统日志都在那里,但作为 ASL 的一部分。

Matthew Schinckel 在他的回答中提到的控制台是 ASL 上的 GUI。 它将向您显示数据库中存在的任何消息,这些消息是通过侧边栏中列出的查询获取的。 默认有两个查询; 一个仅显示使用控制台工具发送的消息(如 NSLog 使用的等),而另一个则显示所有日志消息。 查看所有消息查询; 您可能会在那里找到您的消息。

这个“全部”确实带有星号。 如果您查看 /etc/asl.conf,您将看到这一行:

# save everything from emergency to notice
? [<= Level notice] store

幸运的是,在您的情况下,该消息将通过此检查,因为警告优先于通知(数量较少)。

Mac OS X implements a superset of syslog's functionality. All of syslog is there, but as part of ASL.

Console, mentioned by Matthew Schinckel in his answer, is the GUI on ASL. It'll show you any messages that exist in the database, as fetched by queries listed in the sidebar. There are two queries by default; one only shows messages sent with the Console facility (as used by NSLog, among other things), whereas the other shows all log messages. Check the all-messages query; you'll probably find your message there.

That “all” does come with an asterisk. If you look in /etc/asl.conf, you'll see this line:

# save everything from emergency to notice
? [<= Level notice] store

Fortunately, in your case, the message will pass this check, since warning outranks (is a lesser number than) notice.

对你再特殊 2024-07-16 20:25:51

如果您需要复杂的 syslog 分析(在终端中每小时导航、正则表达式、与其他文件进行实时比较,甚至通过 syslog 运行 SQL)lnav 会无缝地为您提供它。

安装:

brew install lnav

使用:

lnav /var/log/system.log

UI 本身:

在此处输入图像描述

If you need complex syslog analysis (navigation hour by hour in terminal, regexp, comparing in real time w\ other files or even running SQL over syslog) lnav would seamlessly provide it for you.

Installation:

brew install lnav

Usage:

lnav /var/log/system.log

UI itself:

enter image description here

旧梦荧光笔 2024-07-16 20:25:51

基于 Charlie 的回答,我想补充一点,您应该查看 syslog.conf(5) 的联机帮助页,并查看文件 /etc/syslog.conf (这是系统日志配置默认定义的地方,据我所知,在 OS X 10.5.x 上也是如此)。

Building on Charlie's answer, I would like to add that you should take a look at the manpage of syslog.conf(5) and also take a peek at the file /etc/syslog.conf (which is where the syslog configuration is defined by default and also, as I see it, on OS X 10.5.x).

涙—继续流 2024-07-16 20:25:51

检查程序中某处对 openlog 的调用。 调用 openlog 后,syslog 会将其输出保存到该日志文件而不是默认位置。

Check for a call to openlog somewhere in the program. After a call to openlog, syslog will save its output to that log file instead of the default location.

别想她 2024-07-16 20:25:51

大苏尔

不幸的是,上述答案都不适合我。

对我有用的:

从终端使用mail程序访问的系统邮件包含电子邮件中的所有/usr/sbin/cron日志。

Big Sur

Unfortunately, non of the stated answers worked for me.

What Worked for me:

The system mail accessed using the mail program from the terminal had all the /usr/sbin/cron logs in emails.

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