GithubHelp home page GithubHelp logo

strace-with-colors's Introduction

strace, but with colors

This patch adds colored output to the strace program.

The --color option

From strace --help

  --color[=WHEN]
                 colorize the output; WHEN can be 'always', 'auto' (default), or 'never'
  • always will always colorize the output
  • never will never colorize the output
  • auto will only colorize the output when standard output is connected to a terminal

Using --output or setting the NO_COLOR environment variable will disable the colored output.

Installation

Arch Linux

strace-with-colors package from AUR

git clone https://aur.archlinux.org/strace-with-colors.git
cd strace-with-colors
makepkg -si

Fedora Linux

strace-with-colors package from Copr

dnf copr enable xfgusta/strace-with-colors
dnf install strace-with-colors

From source

Clone the strace git repository and go to the directory

git clone https://github.com/strace/strace
cd strace

Checkout the tag v6.3 (latest version)

git checkout tags/v6.3

Get the patch source here and apply it

curl -O https://raw.githubusercontent.com/xfgusta/strace-with-colors/main/strace-with-colors.patch
git apply strace-with-colors.patch

Now you are ready to build and install strace with colors!

./bootstrap
./configure --enable-mpers=no
make install

You may need to install some dependencies before, like:

  • make
  • autoconf
  • automake
  • gcc
  • ...

You can actually check all the strace installation instructions here.

The program will be in the /usr/local/bin directory. You can uninstall it running make uninstall.

Screenshot

Color scheme

Here is the color scheme used in the screenshot above:

FG Name Color
0 Black #2d3139
1 Red #e06c75
2 Green #98c379
3 Yellow #e5c07b
4 Blue #528bff
5 Magenta #c678dd
6 Cyan #56b6c2
7 White #d7dae0

strace-with-colors's People

Contributors

ma27 avatar xfgusta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

strace-with-colors's Issues

Bringing this upstream

I'd love to see this in upstream strace, you should consider submitting it for review soon so the patch can be improve until the maintainers are happy :)

Thanks for your work, I've been missing colored output (and relying for vim-coloring instead) for years.

Does not apply to strace from kernel 6.1

strace> building '/nix/store/ml18vglsg03g3p0w88jmr1w6r556ig9r-strace-6.0-1.drv'
strace> unpacking sources
strace> unpacking source archive /nix/store/7937gfphr8197i8dy02rqxqzdwybxh1z-strace-6.1.tar.xz
strace> source root is strace-6.1
strace> setting SOURCE_DATE_EPOCH to timestamp 1670869767 of file strace-6.1/doc/.strace.1.in.date
strace> patching sources
strace> applying patch /nix/store/gd8ycg96qdxxlvi27gmsvrrx75mpw0lb-strace-with-colors-6.0-1
strace> patching file src/futex.c
strace> Hunk #2 FAILED at 114.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/futex.c.rej
strace> patching file src/ioctl.c
strace> Hunk #2 succeeded at 450 (offset 1 line).
strace> patching file src/ipc.c
strace> Hunk #2 FAILED at 18.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/ipc.c.rej
strace> patching file src/ipc_shm.c
strace> Hunk #2 FAILED at 48.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/ipc_shm.c.rej
strace> patching file src/mem.c
strace> Hunk #2 FAILED at 81.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/mem.c.rej
strace> patching file src/memfd_create.c
strace> Hunk #2 FAILED at 42.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/memfd_create.c.rej
strace> patching file src/mmsghdr.c
strace> patching file src/netlink.c
strace> Hunk #2 FAILED at 181.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/netlink.c.rej
strace> patching file src/netlink_netlink_diag.c
strace> Hunk #2 FAILED at 62.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/netlink_netlink_diag.c.rej
strace> patching file src/numa.c
strace> Hunk #1 FAILED at 8.
strace> Hunk #2 FAILED at 95.
strace> 2 out of 2 hunks FAILED -- saving rejects to file src/numa.c.rej
strace> patching file src/perf.c
strace> Hunk #2 FAILED at 160.
strace> Hunk #3 FAILED at 191.
strace> 2 out of 3 hunks FAILED -- saving rejects to file src/perf.c.rej
strace> patching file src/personality.c
strace> Hunk #1 FAILED at 18.
strace> 1 out of 1 hunk FAILED -- saving rejects to file src/personality.c.rej
strace> patching file src/print_fields.h
strace> Hunk #3 succeeded at 244 (offset 48 lines).
strace> patching file src/print_instruction_pointer.c
strace> Hunk #1 FAILED at 14.
strace> 1 out of 1 hunk FAILED -- saving rejects to file src/print_instruction_pointer.c.rej
strace> patching file src/print_syscall_number.c
strace> Hunk #1 FAILED at 6.
strace> 1 out of 1 hunk FAILED -- saving rejects to file src/print_syscall_number.c.rej
strace> patching file src/printmode.c
strace> patching file src/ptrace.c
strace> Hunk #2 FAILED at 77.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/ptrace.c.rej
strace> patching file src/s390.c
strace> Hunk #3 succeeded at 621 (offset -1 lines).
strace> Hunk #4 succeeded at 792 (offset -1 lines).
strace> Hunk #5 succeeded at 807 (offset -1 lines).
strace> Hunk #6 succeeded at 923 (offset -1 lines).
strace> Hunk #7 succeeded at 1133 (offset -1 lines).
strace> Hunk #8 FAILED at 1285.
strace> Hunk #9 succeeded at 1350 (offset 1 line).
strace> Hunk #10 FAILED at 1516.
strace> Hunk #11 FAILED at 1530.
strace> 3 out of 11 hunks FAILED -- saving rejects to file src/s390.c.rej
strace> patching file src/signal.c
strace> patching file src/sockaddr.c
strace> Hunk #3 FAILED at 575.
strace> Hunk #4 succeeded at 629 with fuzz 1.
strace> Hunk #5 succeeded at 664 with fuzz 1.
strace> 1 out of 5 hunks FAILED -- saving rejects to file src/sockaddr.c.rej
strace> patching file src/strace.c
strace> Hunk #4 succeeded at 714 (offset 2 lines).
strace> Hunk #5 succeeded at 756 (offset 2 lines).
strace> Hunk #6 succeeded at 785 (offset 2 lines).
strace> Hunk #7 succeeded at 909 (offset 5 lines).
strace> Hunk #8 succeeded at 927 (offset 5 lines).
strace> Hunk #9 succeeded at 2284 (offset 5 lines).
strace> Hunk #10 succeeded at 2310 (offset 5 lines).
strace> Hunk #11 succeeded at 2418 (offset 5 lines).
strace> Hunk #12 succeeded at 2951 (offset 5 lines).
strace> patching file src/swapon.c
strace> Hunk #2 FAILED at 25.
strace> 1 out of 2 hunks FAILED -- saving rejects to file src/swapon.c.rej
strace> patching file src/syscall.c
strace> Hunk #4 succeeded at 836 (offset 1 line).
strace> Hunk #5 succeeded at 909 (offset 1 line).
strace> Hunk #6 succeeded at 931 (offset 1 line).
strace> Hunk #7 succeeded at 949 (offset 1 line).
strace> Hunk #8 FAILED at 977.
strace> 1 out of 8 hunks FAILED -- saving rejects to file src/syscall.c.rej
strace> patching file src/sysctl.c
strace> Hunk #1 FAILED at 23.
strace> Hunk #2 FAILED at 39.
strace> Hunk #3 FAILED at 140.
strace> Hunk #4 FAILED at 156.
strace> 4 out of 4 hunks FAILED -- saving rejects to file src/sysctl.c.rej
strace> patching file src/term.c
strace> Hunk #1 succeeded at 17 with fuzz 2.
strace> Hunk #2 FAILED at 37.
strace> Hunk #3 FAILED at 68.
strace> Hunk #4 FAILED at 96.
strace> Hunk #5 FAILED at 109.
strace> Hunk #6 FAILED at 200.
strace> 5 out of 6 hunks FAILED -- saving rejects to file src/term.c.rej
strace> patching file src/util.c
strace> Hunk #2 FAILED at 403.
strace> Hunk #3 FAILED at 668.
strace> Hunk #4 succeeded at 1066 (offset 4 lines).
strace> Hunk #5 FAILED at 1112.
strace> Hunk #6 FAILED at 1166.
strace> Hunk #7 succeeded at 1220 (offset 4 lines).
strace> Hunk #8 succeeded at 1261 (offset 4 lines).
strace> Hunk #9 succeeded at 1319 (offset 4 lines).
strace> Hunk #10 succeeded at 1459 (offset 4 lines).
strace> Hunk #11 FAILED at 1622.
strace> Hunk #12 FAILED at 1758.
strace> 6 out of 12 hunks FAILED -- saving rejects to file src/util.c.rej
strace> patching file src/wait.c
strace> Hunk #4 FAILED at 67.
strace> 1 out of 4 hunks FAILED -- saving rejects to file src/wait.c.rej
strace> patching file src/xlat.c
strace> Hunk #4 succeeded at 442 with fuzz 1.
strace> patching file src/color.h

configure: exit 77

sudo ./configure --enable-mpers=no checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether to enable maintainer-specific portions of Makefiles... no checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for gcc... gcc checking whether the C compiler works... no configure: error: in /data/scripts/strace':
configure: error: C compiler cannot create executables
See config.log' for more details

cat config.log
....
configure: exit 77

solution :
sudo apt-get install build-essential

Update patches to 5.19

The patches no longer apply to 5.19. It would be super cool if you could update them.

Writing to file should strip escape codes

When I am supplying strace with -o and write the log to a file the escape codes are also written to the file. I think they should be stripped before to easily search and navigate the file with a text editor.

Use automatic coloring by default

Like many other tools do (e.g. ls), this should also automatically coloring by checking if the terminal is a tty, and then colorize.
The --color cli option should then have three values:

  • auto (default, based on the ioctl(stdout, TCGETS, ...) being -1 ENOTTY or 0
  • never (turn off coloring)
  • always (turn on coloring)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.