2024年4月25日星期四

[MacOS]Add auto log function to terminal.app

Boring with Mac terminal color of white and black?

Ok, you can change the theme.

I like the homebrew theme, but it has too bright color for text.

OK, that is not my point.

For some reason, I need to add a function for terminal.app on Mac to record the command and screen output as what I can see.

You can go to the menu, [Terminal] -> [Configuration] -> Click the theme you are using [Shell]. Then you will see a startup shell command input.

 now=`date +%Y%m%d%H%M%S`;logpath=~/scriptlogs/script_${now}.txt;script ${logpath}

Just copy and paste above. It will add auto execute script when terminal.app start up and execute it with script command of unix.

You also can change the following path to where you want to keep your log. "~/scriptlogs/"  

Then check the execute in shell. You need shutdown terminal.app and start it again.

Now you have an auto log for Mac terminal.app.

But most people will ignore one thing...

If you try to execute the command [cat the log] in the terminal.app, you will get into a loop...and a fast increased size log file till your system crash. 

Because the screen out put will be written to log imediately and it was also shown as standard output then it will be recorded to log again and again. 


没有评论:

发表评论