![](/img/trans.png)
[英]Is there a way to use more elements than display in an Out-GridView array
[英]Use Out-gridview to display Log
我对 powershell 脚本很陌生。 我想使用 out-gridview 在 gridview 中显示日志文件。
假设我有一个非常简单的脚本,例如
$logFile = "logs\myCoolLogFile.log";
gc -wait $logFile | Out-GridView -Wait
这将在单个单元格中显示每一行。 我的日志格式如下:
LEVEL TIMESTAMP LOGGERNAME [THREAD]: MESSAGE
每个条目由一个或多个空格分隔(但如果更合适,我可以轻松地将其更改为由一个制表符分隔)。 该消息可能包含额外的空格。 以前的条目从不包含空格。
我想为LEVEL
、 TIMESTAMP
等设置不同的列。但我不确定如何实现这一点。 任何帮助表示赞赏。
编辑:按照@jisaak 的要求,这是我的日志示例,其中包含多行消息:
WARN 09:53:49.938 n.s.e.CacheManager [StartStop-Thread] Creating a new instance of CacheManager using the diskStorePath "C:\temp" which is already used by an existing CacheManager.
The source of the configuration was net.sf.ehcache.config.generator.ConfigurationSource$DefaultConfigurationSource@48666bf4.
The diskStore path for this CacheManager will be set to C:\temp\ehcache_auto_created_1461052429938.
Edit2:现在,我考虑一下,我想如果完全跳过不包含足够列的行是可以接受的。 但我也确实需要这种行为的帮助。
您可以使用ConvertFrom-Csv cmdlet 来转换您的日志:
$logFile = "logs\myCoolLogFile.log";
gc $logFile | ConvertFrom-Csv -Delimiter ' ' | Out-GridView
为什么要在Get-Content
cmdlet 上使用-wait
开关?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.