![]() ![]() Newer versions of bash also support a fancier syntaxįor redirecting both standard output and standardĮrror to the same file: the &> notation ls docs &> output. Or we could instead use 2>&1 which is a fancy syntaxįor saying "redirect standard error to the same Standard error to the same file, we could do ls docs > output.txt 2> output.txt If we wanted to redirect both standard output and cat bees.txt ants.txt > insects.txt 2> error.txt Insects.txt, and redirecting standard error to a file called error.txt. We can redirect multiple streams at once! In this example, we areĬoncatenating two files, redirecting standard output to a file called To specify 1> to redirect standard output: ( date 1> now.txt = date > now.txt) all together The > operator actually defaults to using 1 as theįile descriptor number, which is why we don't need In both cases, you see the entire log buth with highlighted search term like this: The -f switch could be omitted if no live grep is wanted. If the container logs to stderr, you can pipe them as Edoardo already wrote for a simple grep: docker logs -f 2>&1 | grep -line-buffered -i -E -color "select count\(\*\)|$" * is escaped to disable its special glob functionality, where (, and ) are masked to avoid their regex meaning as group, which is enabled by -E switch.-color highlights the matched parts (seems the default behaviour on my Ubuntu 16.04 LTS, but maybe not on other distributions, so I included it here to be safe).-E is an extended regex pattern, required to apply our pattern that allow us returning also the non matching results.greps -line-buffered switch flushes the output on every line, which is required to grep in real time when docker logs -f is used.docker logs -f tell docker to follow the logs, so the filter applys also to new entrys like when viewing it using tail -f.This is possible with -E switch and some regex:įor example, the following snippet search for all queries that contain COUNT(*) as well as count(*): docker logs -f | grep -line-buffered -i -E -color "select count\(\*\)|$" 8 Answers Sorted by: 116 I think this solution is easier and better, use directly the function findstr: alias findstr -i Write You can also make an alias to use grep word: new-alias grep findstr Share Follow answered at 8:54 Roi 1,424 2 11 13 5 This is the most intuitive and easy to remember approach among all the other answers. But with a simple grep I can't see the entire SQL statement since it's a multi line statement. ![]() In my case I want to highlight COUNT(*) statements. Especially on productive installations where a lot of log output is generated. Additionally, I found it usefull to highlight some terms that I'm searching for in the logs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |