Logging 编写不包含';t在Powershell中换行到命令宽度
我想把大量的数据写入一个输出文件。我是这样做的Logging 编写不包含';t在Powershell中换行到命令宽度,logging,powershell,word-wrap,Logging,Powershell,Word Wrap,我想把大量的数据写入一个输出文件。我是这样做的 Start-Transcript -Path $TargetDir\RunUnitTests.log -Width 1000000 Write-Verbose "five million character lines and stuff" 这非常有效,除了输出自动包装到控制台的标准宽度之外,这使得日志看起来非常糟糕 我找到了一个解决方案,删除了链接 ,但它太复杂了,我不想把它放在我的脚本下面的注释#Thar be dragons 有更好的方法吗
Start-Transcript -Path $TargetDir\RunUnitTests.log -Width 1000000
Write-Verbose "five million character lines and stuff"
这非常有效,除了输出自动包装到控制台的标准宽度之外,这使得日志看起来非常糟糕
我找到了一个解决方案,删除了链接
,但它太复杂了,我不想把它放在我的脚本下面的注释#Thar be dragons
有更好的方法吗?这里有一个非常简单的解决方法,它基于
写主机
,没有这样的问题。在会话开始时,安装/dot source以替换默认的Write Verbose
:
function global:Write-Verbose
(
[string]
$Message
)
{
# check $VerbosePreference variable
if ($VerbosePreference -ne 'SilentlyContinue') {
# do this via Write-Host
Write-Host "VERBOSE: $Message" -ForegroundColor 'Yellow'
}
}
然后根据需要执行此操作:
$VerbosePreference = 'Continue'
Start-Transcript -Path .\RunUnitTests.log
Write-Verbose ("verbose writes five million character lines and stuff. " * 20)
也就是说:它考虑了$VerbosePreference
,它以黄色写入主机,成绩单输出没有包装,仍然标记为VERBOSE
**********************
Windows PowerShell Transcript Start
Start time: 20101105055855
**********************
Transcript started, output file is .\RunUnitTests.log
VERBOSE: verbose writes ... <long line text> ... and stuff.
**********************
Windows PowerShell Transcript End
End time: 20101105055855
**********************
**********************
Windows PowerShell成绩单启动
开始时间:201011055855
**********************
转录本已启动,输出文件为。\RunUnitTests.log
冗长的:冗长的写作。。。等等。
**********************
Windows PowerShell转录本结束
结束时间:201011055855
**********************
您可能还希望修饰参数以支持管道化[参数(位置=0,强制=$true,ValueFromPipeline=$true)]
有关防止在所有详细输出中包装的相关问题,而不仅仅是从显式调用写入详细输出,请参阅。