Category Archives: Mac

Show logs on macOS(10.12 Sierra or later)

Overview

Use `log`.

Streaming (like tail command)

`log stream`

Find from past log

`log show`

See `man log` for detail.

Example

cron

$ log stream --info --predicate 'process == "cron"'
$ log show --info --predicate 'process == "cron"' --start '2017-05-25'

postfix

$ log stream --info --predicate '(process == "smtp") || (process == "smtpd")'
$ log show --info --predicate '(process == "smtp") || (process == "smtpd")' --start '2017-05-25'

If you doesn't know process name to specify

$ log show --info --start '2017-11-08' | grep 'xxx'

and guess process name.

Many cachegrind.out.xxxxxx were generated in /private/var/tmp and disk space filled up

Recently I found that the free disk space of my Mac OS X (Yosemite) got very small, so I looked into why.

$ sudo du -sh /*

$ sudo du -sh /private/*

$ sudo du -sh /private/var/*

Finally I found that /private/var/tmp contained over 200GB files.
In /private/var/tmp there are many files whose name are such as cachegrind.out.50526.
It is said that these files are generated by Xdebug profiler.
Yes, I use Xdebug from MacPorts.
Xdebug is convenient because it shows stacktrace in error, enables stepping execution (but it needs Eclipse...), and so on.

Then I attempted to delete them with rm but an error occurred.

$ sudo rm cachegrind.out.*
-bash: sudo: Argument list too long

Because the files were too many, shell expansion for "*" caused Argument list too long error.

Therefore I deleted them using find -exec.

$ cd /private/var/tmp
$ sudo find . -name 'cachegrind.out.*' -maxdepth 1 -exec rm {} \;

I got about 200GB free space.

See below for details about find -exec.
Delete or grep the results of find

If this goes on, files will be generated and they will fill up my disk again. So I decided to modify Xdebug setting so that Xdebug profiler will generate output files not in /private/var/tmp but in /tmp directory.
(I also set trace output directory to /tmp)
They will be deleted on rebooting.

/opt/local/etc/php53/php.ini
Add xdebug.profiler_output_dir and xdebug.trace_output_dir.

[xdebug]
xdebug.profiler_enable=On
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.idekey=ECLIPSE_DBGP
xdebug.profiler_output_dir=/tmp/ ; where the profiler output will be written to
xdebug.trace_output_dir=/tmp/ ; where the tracing files will be written to

Xdebug: Documentation.

How to input control characters

Emacs

C-q <Control Character>

Example: Input escape character

C-q C-[

Shell, Vim

Ctrl+V <Control Character>

Example: Input escape character

Ctrl+V Ctrl+[

How to find a letter which should be pressed in combination with Control key?

<Control Character> in above explanation should be input in combination with Control key. The letter which should be input with Control key is a letter which is produced by setting 7th bit of the letter you want to input to 1, that is to say, by adding 0x40(64).
You can find it in `man ascii` etc.

Example:
Escape character is 0x1B(27).
Set 7th bit to 1, i.e. add 0x40(64) and you get 0x5B(91).
0x5B(91) is '['.
Therefore, to input escape character press Ctrl+[.

Line feed is 0x0A(10).
Set 7th bit to 1, i.e. add 0x40(64) and you get 0x4A(74).
0x4A(74) is 'J'.
Therefore, to input line feed press Ctrl+J.

Source: https://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
エスケープ文字の入力方法 - nelnalog.note