macos 在 Mac 上读取系统日志输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/380172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:59:38  来源:igfitidea点击:

Reading syslog output on a Mac

macossyslog

提问by maerics

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.

我有一个为 linux 编写的程序,我正在尝试在我的 MacOS 10.5 机器上构建和运行它。该程序构建和运行没有问题,但是它对 syslog 进行了多次调用。我知道 syslogd 正在我的 Mac 上运行,但是我似乎无法找到我的 syslog 调用输出到的位置。

The syslog calls are of the form

系统日志调用的形式为

syslog (LOG_WARNING, "Log message");

Any idea where I might find my log output?

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

回答by maerics

/var/log/system.log

/var/log/system.log

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

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

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

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

回答by Matthew Schinckel

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

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

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

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

enter image description here

在此处输入图片说明

回答by Charlie Martin

When in doubt, there's always man syslog.

当有疑问时,总会有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.

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

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

您还可以通过syslog(1)读取消息,或使用类似的命令创建测试消息

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

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

使用 P 的严重性(“恐慌”),您会立即在控制台上收到一条令人兴奋的消息。

回答by Mecki

Maybe interesting to note: Apple was using a real syslogdin the past but meanwhile all of this has switched to ASL (Apple System Log). The syslogcommand 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 logcommand.

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

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

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

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

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

查看man log您可以执行的所有操作、它知道的所有参数以及您可以过滤的属性。

回答by Peter Hosey

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

Mac OS X 实现了 syslog 功能的超集。所有 syslog 都在那里,但作为 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 alllog messages. Check the all-messages query; you'll probably find your message there.

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

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

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

# 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.

幸运的是,在您的情况下,该消息将通过此检查,因为警告高于(小于)通知。

回答by ayaz

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).

以查理的回答为基础,我想补充一点,您应该查看 的联机帮助页syslog.conf(5)并查看文件/etc/syslog.conf(默认情况下定义系统日志配置的位置,而且在我看来,在 OS X 上也是如此) 10.5.x)。

回答by Peter Hosey

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

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