feat: Add protobuf text log format and Go formatter
- Create a Go program to parse and format protobuf text logs. - Add a new log file in the text format for the current session.
This commit is contained in:
parent
f93e54df6a
commit
0989784018
|
@ -0,0 +1,64 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/lib/protobuf/chatpb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Fprintf(os.Stderr, "Usage: go run format_log.go <path_to_log_file>\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
filename := os.Args[1]
|
||||
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading file %s: %v", filename, err)
|
||||
}
|
||||
|
||||
// Use the existing robust unmarshaler from the chatpb package.
|
||||
logData, err := chatpb.UnmarshalChatsTEXT(data)
|
||||
if err != nil {
|
||||
log.Fatalf("Error unmarshaling log file %s: %v", filename, err)
|
||||
}
|
||||
|
||||
// Print header information.
|
||||
fmt.Printf("---\n")
|
||||
fmt.Printf("Log File: %s\n", filename)
|
||||
fmt.Printf("UUID: %s\n", logData.GetUuid())
|
||||
fmt.Printf("Version: %s\n", logData.GetVersion())
|
||||
fmt.Println(strings.Repeat("-", 40))
|
||||
|
||||
// Iterate through and format each chat entry.
|
||||
for _, chat := range logData.GetChats() {
|
||||
// Format the timestamp.
|
||||
var formattedTime string
|
||||
if ctime := chat.GetCtime(); ctime != nil {
|
||||
// Convert protobuf timestamp to Go's time.Time.
|
||||
t := ctime.AsTime()
|
||||
formattedTime = t.Format("2006-01-02 15:04:05") // YYYY-MM-DD HH:MM:SS
|
||||
} else {
|
||||
formattedTime = "No Timestamp"
|
||||
}
|
||||
|
||||
// Format the author. The .proto file defines an enum for this.
|
||||
author := chat.GetFrom().String()
|
||||
|
||||
fmt.Printf("[%s] (%s):\n", author, formattedTime)
|
||||
fmt.Printf("%s\n\n", chat.GetContent())
|
||||
|
||||
// Bonus: Handle tables if they exist in a chat message.
|
||||
if table := chat.GetTable(); table != nil {
|
||||
fmt.Println(" --- Table Data ---")
|
||||
for _, row := range table.GetRows() {
|
||||
fmt.Printf(" | %s |\n", strings.Join(row.GetFields(), " | "))
|
||||
}
|
||||
fmt.Println(" ------------------\n")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
uuid: "b2c3d4e5-f6a7-4b5c-8d9e-1f2a3b4c5d6e"
|
||||
version: "v0.0.1 go.wit.com/lib/protobuf/chatpb"
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724162400 # Approx time for 2025-08-20
|
||||
}
|
||||
content: "your last attempt to reformat today's log ran for several minutes, then timed out. All I see is \"[API Error: terminated]\". Maybe there are resource limits that were exhasted?"
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724162460
|
||||
}
|
||||
content: "You are absolutely correct, and my apologies for that failure. Your diagnosis is spot on. My attempt to regenerate the entire conversation with the exact decorative CLI formatting was too ambitious for a single operation."
|
||||
}
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724162520
|
||||
}
|
||||
content: "sounds good. better yet. maybe we can make a GO program to format the output. That way you can write out JSON files and the GO program can try to format the log files. In this case then, instead of .log files, save the information in .json files in the log/ directory. (don't delete the existing .log files)"
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724162580
|
||||
}
|
||||
content: "That's an excellent idea. It's a much more robust and flexible approach. I will proceed with this plan..."
|
||||
}
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724163000
|
||||
}
|
||||
content: "I made a different log file format to try. the file format is log/sample.text take a look at it. if you can make a simple example log file with the same format. You can test the parsing of that file with \"GO111MODULE=off go run parse_protobuf_log.go log/sample.text\". This file format should be easier to work with than JSON."
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724163060
|
||||
}
|
||||
content: "Understood. This is a great idea; a simpler, custom text format will be much more reliable than my attempts with JSON."
|
||||
}
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724163300
|
||||
}
|
||||
content: "since this file format is more robust, can you attempt again to make a GO program to output our conversations as we discussed earlier and failed due to problems with JSON file formats? (also, you are correct, this is a protobuf TEXT file format. You can look at the .proto file with the path included here."
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724163360
|
||||
}
|
||||
content: "Excellent. I am confident I can do this successfully now that we have a well-defined and reliable file format to work with. A Go program to format this protobuf text will be much more robust."
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
uuid: "a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d"
|
||||
version: "v0.0.1 go.wit.com/lib/protobuf/chatpb"
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724160000 # Approx time for 2025-08-20
|
||||
}
|
||||
content: "We need to generate a .gds file for the sky130 of a linux capabile riscv core. What is a good option?"
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724160060
|
||||
}
|
||||
content: "Excellent question. The best and most well-supported option for this is the combination of the Rocket Chip generator with the OpenLANE RTL-to-GDSII flow."
|
||||
}
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724160120
|
||||
}
|
||||
content: "if I do 2 or 4 cores with those size L1 & L2 caches, how many transistors will it be and how large of a footprint on the wafer will it take up?"
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724160180
|
||||
}
|
||||
content: "2-Core SoC: Plausible but challenging. Estimated ~10 million transistors and a footprint of ~3.52 mm². 4-Core SoC: Extremely difficult and likely infeasible. Estimated ~13.0 million transistors and a footprint of ~6.04 mm²."
|
||||
}
|
||||
Chats: {
|
||||
from: USER
|
||||
ctime: {
|
||||
seconds: 1724160240
|
||||
}
|
||||
content: "I mean the sky130 chip with 12 million transisters, 6-10mm and 4 riscv cores. How much power will that draw and how hot?"
|
||||
}
|
||||
Chats: {
|
||||
from: GEMINI
|
||||
ctime: {
|
||||
seconds: 1724160300
|
||||
}
|
||||
content: "The power draw will be dramatically lower, likely in the 200-500 milliwatt range under a typical load. It will get warm, but it will not require a heat sink for basic operation."
|
||||
}
|
Loading…
Reference in New Issue