Skip to content

Commit

Permalink
DecodeUefiLog separate by size feature
Browse files Browse the repository at this point in the history
  • Loading branch information
YiTa-AMI committed Feb 19, 2025
1 parent f55d046 commit ffa4e85
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
42 changes: 37 additions & 5 deletions AdvLoggerPkg/Application/DecodeUefiLog/DecodeUefiLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tempfile
import traceback
import copy
import os

from win32com.shell import shell
from edk2toollib.os.uefivariablesupport import UefiVariable
Expand Down Expand Up @@ -1036,6 +1037,8 @@ def main():
help="Path to binary Output LogFile")
parser.add_argument("-s", "--StartLine", dest="StartLine", default=0, type=int,
help="Print starting at StartLine")
parser.add_argument("-size", "--FileSize", dest="FileSize", default=0, type=int,
help="Output Separate LogFile by KB Size")

options = parser.parse_args()

Expand All @@ -1053,11 +1056,40 @@ def main():
lines = advlog.ProcessMessages(InFile, options.StartLine)

if options.OutFilePath is not None:
OutFile = open(options.OutFilePath, "w", newline=None)
OutFile.writelines(lines)
OutFile.close()
CountOfLines = len(lines)
print(f"{CountOfLines} lines written to {options.OutFilePath}")
if options.FileSize == 0:
OutFile = open(options.OutFilePath, "w", newline=None)
OutFile.writelines(lines)
OutFile.close()
CountOfLines = len(lines)
print(f"{CountOfLines} lines written to {options.OutFilePath}")
else:
SeparatedFilePath:str = options.OutFilePath
FilePathPart = os.path.splitext(SeparatedFilePath)
MaxSize = options.FileSize * 1000
CurrentFileSize = 0
SeparateFileIndex = 1
CountOfLines = 0
SeparatedFilePath = FilePathPart[0] + '_' + str(SeparateFileIndex) + FilePathPart[1]
OutFile = open(SeparatedFilePath, "w", newline=None)

for LineIndex in lines:
CurrentLineSize = len(LineIndex.encode('utf-8'))
if CurrentFileSize + CurrentLineSize > MaxSize:
OutFile.close()
print(f"{CountOfLines} lines written to {SeparatedFilePath}")
CountOfLines = 1
SeparateFileIndex += 1
SeparatedFilePath = FilePathPart[0] + '_' + str(SeparateFileIndex) + FilePathPart[1]
OutFile = open(SeparatedFilePath, "w", newline=None)
OutFile.writelines(LineIndex)
CurrentFileSize = CurrentLineSize
else:
OutFile.writelines(LineIndex)
CountOfLines += 1
CurrentFileSize += CurrentLineSize

OutFile.close()
print(f"{CountOfLines} lines written to {SeparatedFilePath}")

except Exception:
print("Error processing log output.")
Expand Down
6 changes: 6 additions & 0 deletions AdvLoggerPkg/Application/DecodeUefiLog/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Decode a raw file into a text file:
DecodeUefiLog -l RawLog.bin -o NewLogFIle.txt
```

Decode lines and separate to multiple files by Kb size -size:

```.sh
DecodeUefiLog -size 30 -o NewLogFile.txt
```

---

## Copyright
Expand Down

0 comments on commit ffa4e85

Please sign in to comment.