java 如何在 ubuntu 中查看系统日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44394034/
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-11-03 08:09:03  来源:igfitidea点击:

How to view syslog in ubuntu?

javalinuxubuntuloggingsys

提问by Tony

Follow up from this question, LogBack Syslog not working java

从这个问题跟进,LogBack Syslog not working java

I use command below to view syslogin ubuntu16.04 but get below result. Is it the correct way to view?

我使用下面的命令syslogubuntu16.04 中查看但得到以下结果。这是正确的观看方式吗?

user@xxx:~$ tail -f /var/log/syslog Jun  6 23:08:50 xxx systemd[1]:
Starting Hostname Service... Jun  6 23:08:50 xxx dbus[889]: [system]
Successfully activated service 'org.freedesktop.hostname1' Jun  6
23:08:50 xxx systemd[1]: Started Hostname Service. Jun  6 23:09:41 xxx
gnome-session[2645]: (nautilus:2860): Gtk-WARNING **: Attempting to
read the recently used resources file at
'/home/xxx/.local/share/recently-used.xbel', but the parser failed:
Failed to open file '/home/xxx/.local/share/recently-used.xbel':
Permission denied. Jun  6 23:09:41 xxx org.gtk.vfs.Daemon[2508]:
(gvfsd-recent:15282): Gtk-WARNING **: Attempting to read the recently
used resources file at '/home/xxx/.local/share/recently-used.xbel',
but the parser failed: Failed to open file
'/home/xxx/.local/share/recently-used.xbel': Permission denied. Jun  6
23:09:41 xxx gnome-session[2645]: (zeitgeist-datahub:3069):
Gtk-WARNING **: Attempting to read the recently used resources file at
'/home/xxx/.local/share/recently-used.xbel', but the parser failed:
Failed to open file '/home/seng/.local/share/recently-used.xbel':
Permission denied. Jun  6 23:09:49 xxx gnome-session[2645]:
(nautilus:2860): Gtk-WARNING **: Attempting to read the recently used
resources file at '/home/xxx/.local/share/recently-used.xbel', but the
parser failed: Failed to open file
'/home/xxx/.local/share/recently-used.xbel': Permission denied. Jun  6
23:09:49 xxx org.gtk.vfs.Daemon[2508]: (gvfsd-recent:15282):
Gtk-WARNING **: Attempting to read the recently used resources file at
'/home/xxx/.local/share/recently-used.xbel', but the parser failed:
Failed to open file '/home/xxx/.local/share/recently-used.xbel':
Permission denied. Jun  6 23:09:49 xxx gnome-session[2645]:
(zeitgeist-datahub:3069): Gtk-WARNING **: Attempting to read the
recently used resources file at
'/home/seng/.local/share/recently-used.xbel', but the parser failed:
Failed to open file '/home/xxx/.local/share/recently-used.xbel':
Permission denied. Jun  6 23:17:01 xxx CRON[18877]: (root) CMD (   cd
/ && run-parts --report /etc/cron.hourly)

Try cat /var/log/syslog(small part of the output)

尝试cat /var/log/syslog(输出的一小部分)

Jun  6 23:37:26 xxx whoopsie[1040]: [23:37:26] online
Jun  6 23:37:26 xxx avahi-daemon[1023]: Registering new address record for 2001:e68:4424:afab:c31f:c843:2351:c58 on wlp6s0.*.
Jun  6 23:37:28 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 4340ms.
Jun  6 23:37:32 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 9080ms.
Jun  6 23:37:41 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 17540ms.
Jun  6 23:37:59 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 34190ms.
Jun  6 23:38:09 xxx NetworkManager[1013]: <warn>  [1496763489.9447] dhcp6 (wlp6s0): request timed out
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9448] dhcp6 (wlp6s0): state changed unknown -> timeout
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9456] dhcp6 (wlp6s0): canceled DHCP transaction, DHCP client pid 19397
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9456] dhcp6 (wlp6s0): state changed timeout -> done
user@xxx:/$ 

Try cat /var/log/syslog | tail -f

尝试 cat /var/log/syslog | tail -f

user@xxx:/$ cat /var/log/syslog | tail -f
Jun  6 23:37:26 xxx whoopsie[1040]: [23:37:26] online
Jun  6 23:37:26 xxx avahi-daemon[1023]: Registering new address record for 2001:e68:4424:afab:c31f:c843:2351:c58 on wlp6s0.*.
Jun  6 23:37:28 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 4340ms.
Jun  6 23:37:32 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 9080ms.
Jun  6 23:37:41 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 17540ms.
Jun  6 23:37:59 xxx dhclient[19397]: XMT: Solicit on wlp6s0, interval 34190ms.
Jun  6 23:38:09 xxx NetworkManager[1013]: <warn>  [1496763489.9447] dhcp6 (wlp6s0): request timed out
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9448] dhcp6 (wlp6s0): state changed unknown -> timeout
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9456] dhcp6 (wlp6s0): canceled DHCP transaction, DHCP client pid 19397
Jun  6 23:38:09 xxx NetworkManager[1013]: <info>  [1496763489.9456] dhcp6 (wlp6s0): state changed timeout -> done
user@xxx:/$ 

回答by Dmitriusan

Looks like you are trying to read syslogfrom Java, not from an interactive terminal. The text looks like a correct output, but with smashed formatting.

看起来您正在尝试syslog从 Java读取,而不是从交互式终端读取。文本看起来像一个正确的输出,但格式被破坏了。

tail -fis good for interactive terminals.

tail -f适用于交互式终端。

Try cat /var/log/syslog, or just open /var/log/syslogas a file (if your process has enough permissions).

尝试cat /var/log/syslog,或仅/var/log/syslog作为文件打开(如果您的进程有足够的权限)。

回答by slim

In a normal terminal window (in Ubuntu, normally Gnome Terminal), what you've done - sudo tail /var/log/syslogshould display with newlines such that date/time stamps line up on the left.

在普通终端窗口(在 Ubuntu 中,通常是 Gnome 终端)中,您所做的 - sudo tail /var/log/syslog应该显示换行符,以便日期/时间戳在左侧排列。

Either you're not using a normal terminal window, or some control characters have knocked your terminal into a state where newlines don't display properly.

要么您没有使用普通的终端窗口,要么某些控制字符使您的终端进入无法正确显示换行符的状态。

If you're using something other than a terminal window (perhaps something in your IDE?), then use a normal one instead.

如果您使用的不是终端窗口(也许是您的 IDE 中的某些东西?),那么请改用普通窗口。

tail -f /var/log/syslogis for following along as the file grows.

tail -f /var/log/syslog用于跟随文件的增长。

You can dump the whole of the file into the terminal with cat /var/log/syslog.

您可以将整个文件转储到终端中cat /var/log/syslog

You can interactively scroll through the file with less /var/log/syslog.

您可以使用 交互式滚动文件less /var/log/syslog

If you prefer to use a GUI editor, you can open /var/log/syslogin a text editor like gEdit or Atom, although you would have to run those editors as root -- the responsible thing to do would be to copy the file, make it readable by your user, and open that.

如果你更喜欢使用 GUI 编辑器,你可以/var/log/syslog在像 gEdit 或 Atom 这样的文本编辑器中打开,尽管你必须以 root 身份运行这些编辑器——负责任的事情是复制文件,使其可读用户,然后打开它。