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

Primative log support webui.log #138

Closed
matthew73210 opened this issue May 3, 2024 · 3 comments
Closed

Primative log support webui.log #138

matthew73210 opened this issue May 3, 2024 · 3 comments

Comments

@matthew73210
Copy link

Hey, githubs having some issues right now. I can fork, but their backend are down for me so I can't do any pull requests no actully see my fork. Github for vs is having a fit too. So i'll just comment here : 👍

I've added a little function to read webui.log

utils.go -->
Add import "bufio"
Plus the following function

// readWebLog reads the content of the web.log file from the root directory and returns it as a string.
// It returns an error if there is an issue opening or reading the file.
func readWebLog() (string, error) {
	// Open the web.log file
	file, err := os.Open("webui.log")
	if err != nil {
		return "", err
	}
	defer file.Close()

	var content string
	scanner := bufio.NewScanner(file)

	// Read the file line by line and append each line to the content string
	for scanner.Scan() {
		content += scanner.Text() + "\n"
	}

	// Check if there was an error during scanning
	if err := scanner.Err(); err != nil {
		return "", err
	}

	// Return the content of the file
	return content, nil
}

In routes.go

// getLogsHandler handles GET requests to the /logs endpoint.
// It reads the content of the webui.log file and renders the logs view with the content.
func (s *Server) getLogsHandler(c echo.Context) error {
	// Read the content of web.log
	logContent, err := readWebLog()
	if err != nil {
		// Return an HTTP error if there is an issue reading the file
		return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read web.log: "+err.Error())
	}

	// Render the logs view and pass the logContent as data
	return c.Render(http.StatusOK, "logs", map[string]interface{}{
		"LogContent": logContent,
	})
}

In the func (s *Server) initRoutes() {
Add the route

	// Add a route to handle GET requests to the /logs endpoint
	s.Echo.GET("/logs", s.getLogsHandler)

in logs.html

{{define "logs"}}
<span class="col-span-12">
    {{if .LogContent}}
        <pre>{{.LogContent}}</pre>
    {{else}}
        It didn't work
    {{end}}
</span>
{{end}}

It's basic but it does show whats being appended to webui.log (used cat webui.log and i'm getting the same stuff)
Sorry to do it like this but i'll probs forget to do a pull request if i don't do it now. The logs.html needs some work. I did get help from gpt, been ages since i've programmed any webstuff. More used to doing sience stuff (load flow)

@tphakala
Copy link
Owner

tphakala commented May 3, 2024

Thank you! All contributions are welcome no matter how. I will check this during weekend.

@matthew73210
Copy link
Author

I added the small function to utils, but maybe it should go in fileserver?

@matthew73210
Copy link
Author

#153

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

No branches or pull requests

2 participants