Creating a custom change / error log on build

I’m trying to create a custom change and error log file that is generated when Hugo runs a build. The goal is to create a friendly log message for users to see when the site has successfully built or when there has been an error (and what that error is).

Background:
I have an automatic build setup which runs when a user edits a content file (content files are shared via OneDrive). I know this is probably dangerous but it works quite well and is a simple process for business users who don’t have to worry about extra steps like running a build - all they need to do is save.

The problem arises when a user writes some incorrect syntax. When this happens it breaks the build and I have no way to easily tell them what the error is.

I have tried using the Hugo config ‘log’ option with ‘verboseLog’ enabled, but this output doesn’t seem to have the same level of error detail I see on the command line and the browser – specifically I want to show them the error, filename and line number. I’d also like more control of the log format to present a more human friendly output.

I’m currently looking into creating a custom script outside of Hugo to read the output on build and the generate a custom log, but I was hoping there might be an easier way using just Hugo.

This seems like the way to go.

1 Like

The “log to file” and those flags was set up before I started with this, and should probably be revisited. They should log the same as you see in the console, but I notice that if the build fails, the final error is just printed to the console …

That said:

To use that log file for something automatic I guess you still have to do something so you might as well just pipe the console output to a file.

1 Like

If possible, it would be great if error codes were implemented. They allow an error code dictionary, and corresponding knowledge base. They also make automated action easier.
For example, if this had an error code:

INFO 2019/07/23 13:18:54 Translation func for language en not found, use default.

A person could easily lookup more information in a dictionary like this:

And Detail Like this:

1 Like