在 Mac 上读取系统日志输出
我有一个为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
/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
).您可能应该使用 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:
也许有趣的是:Apple 过去使用的是真正的 syslogd,但与此同时,所有这些都已切换到 ASL(Apple 系统日志)。
syslog
命令仍然可用,但它只会访问这一日志。 如果要访问配置的所有日志文件中的 ASL 的所有日志消息,请使用log
命令。例如,以下显示了 Safari 在过去两天内生成的所有日志消息(请耐心等待,可能需要一段时间):
请参阅
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). Thesyslog
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 thelog
command.E.g. the following shows all log messages produced by Safari within the last two days (be patient, can take a while):
See
man log
for all the actions you can perform, all the parameters it knows and what attributes you can filter for.如有疑问,总有
man syslog
。您可以在
/var/log/syslog
中找到您的消息; 我的机器开箱即用,仅包含高级消息,因此您可能需要进行设置。您还可以通过syslog(1)读取消息,或者使用诸如
使用严重性 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
use a severity of P ("panic") and you'll get an exciting message on your console immediately.
Mac OS X 实现系统日志功能的超集。 所有系统日志都在那里,但作为 ASL 的一部分。
Matthew Schinckel 在他的回答中提到的控制台是 ASL 上的 GUI。 它将向您显示数据库中存在的任何消息,这些消息是通过侧边栏中列出的查询获取的。 默认有两个查询; 一个仅显示使用控制台工具发送的消息(如
NSLog
使用的等),而另一个则显示所有日志消息。 查看所有消息查询; 您可能会在那里找到您的消息。这个“全部”确实带有星号。 如果您查看 /etc/asl.conf,您将看到这一行:
幸运的是,在您的情况下,该消息将通过此检查,因为警告优先于通知(数量较少)。
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:
Fortunately, in your case, the message will pass this check, since warning outranks (is a lesser number than) notice.
如果您需要复杂的
syslog
分析(在终端中每小时导航、正则表达式、与其他文件进行实时比较,甚至通过syslog
运行 SQL)lnav 会无缝地为您提供它。安装:
使用:
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 oversyslog
) lnav would seamlessly provide it for you.Installation:
Usage:
UI itself:
基于 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).检查程序中某处对
openlog
的调用。 调用openlog
后,syslog
会将其输出保存到该日志文件而不是默认位置。Check for a call to
openlog
somewhere in the program. After a call toopenlog
,syslog
will save its output to that log file instead of the default location.大苏尔
不幸的是,上述答案都不适合我。
对我有用的:
从终端使用
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.