Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用函数的思维解决这个日志转换过滤的问题 #19

Open
zhongl opened this issue Dec 3, 2013 · 2 comments
Open

用函数的思维解决这个日志转换过滤的问题 #19

zhongl opened this issue Dec 3, 2013 · 2 comments

Comments

@zhongl
Copy link
Member

zhongl commented Dec 3, 2013

假定, tail -f log 会不断输出类似下面日志内容

2013-12-03 10:20:26,889 [nioEventLoopGroup-2-3] DEBUG i.n.handler.logging.LoggingHandler - [id: 0x456ea7b0, /10.68.199.85:36714 => /10.125.48.164:7769] WRITE(42B)
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 34 30 31 0a 76 69 61 3a 74 63 70 3a 2f 2f 31 30 |401.via:tcp://10|
|00000010| 2e 36 38 2e 31 39 39 2e 38 35 3a 33 36 37 31 34 |.68.199.85:36714|
|00000020| 0a 6d 69 64 3a 32 20 30 0a 0a                   |.mid:2 0..      |
+--------+-------------------------------------------------+----------------+
2013-12-03 10:20:26,889 [nioEventLoopGroup-2-3] DEBUG i.n.handler.logging.LoggingHandler - [id: 0x456ea7b0, /10.68.199.85:36714 => /10.125.48.164:7769] FLUSH
2013-12-03 10:20:27,089 [nioEventLoopGroup-2-3] DEBUG i.n.handler.logging.LoggingHandler - [id: 0x456ea7b0, /10.68.199.85:36714 => /10.125.48.164:7769] RECEIVED(406B)

现, 需要写段 scala 脚本, 使得 tail -f log | scala script.scala 后输出:

2013-12-03 10:20:26,889 /10.68.199.85:36714 => /10.125.48.164:7769 WRITE(42B)

401
via:tcp://10.68.199.85:36714
mid:2 0

2013-12-03 10:20:26,889 /10.68.199.85:36714 => /10.125.48.164:7769 FLUSH
2013-12-03 10:20:27,089 /10.68.199.85:36714 => /10.125.48.164:7769 RECEIVED(406B)

你实现了吗?

嗯, 不错! 然我们提升一点难度, 让你的脚本支持一个 关键字 的参数, 使得执行tail -f log | scala script.scala "401"后输出上面的内容不变, 而执行tail -f log | scala script.scala "400"后则输出:

2013-12-03 10:20:26,889 /10.68.199.85:36714 => /10.125.48.164:7769 WRITE(42B)
2013-12-03 10:20:26,889 /10.68.199.85:36714 => /10.125.48.164:7769 FLUSH
2013-12-03 10:20:27,089 /10.68.199.85:36714 => /10.125.48.164:7769 

请务必用函数的思维来实现你的脚本!

@zhongl
Copy link
Member Author

zhongl commented Dec 4, 2013

@zhongl
Copy link
Member Author

zhongl commented Dec 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant