chiubaka / genesis

Creates standardized monorepos and pre-configured project scaffolding for Chiubaka Technologies projects.
2 stars 0 forks source link

Figure out how to get logging in my preset generator #42

Closed chiubaka closed 2 years ago

chiubaka commented 2 years ago

Right now it seems like create-nx-workspace eats logs :/. It's meant to at least output an error.log file if something goes wrong, but I'm having a hard time even consistently getting that.

It would be nice to be able to see what's happening as my generators run so that I can debug problems.

Encountered while trying to get #41 merged in, so relates to #24.

Essentially, I'm having a generator failure on CircleCI, but am not getting enough info from logging to figure out what's going on.

chiubaka commented 2 years ago

Alright, this is getting frustrating as I work on #68 and need more info about what's going on.

Now looking at various JS loggers and trying to decide which to use. Here are some useful articles about the comparison:

Winston seems to be a favorite in terms of popularity, though that's not necessarily a good gauge.

Am thinking that so long as I (mostly) wrap Winston with a thin logging wrapper, it won't be a huge deal if I decide to switch later.

chiubaka commented 2 years ago

I decided to go with Winston. Created a thin wrapper that provides a reasonable API for any logger. Should allow me to mostly abstract away the implementation and configuration of the underlying logger. Most of my code really won't care at all.

chiubaka commented 2 years ago

Bigger question now is this: if I do log output to a file, how do I ensure that that file doesn't get committed with the rest of my generated files?

Doesn't feel like the log file belongs with the repository. Trying to modify .gitignore for this is out because every single generator that outputs to a file (which right now is all of them) would need to duplicate this functionality. I could DRY this up with a utility, but it feels wrong for each individual generator to have to know enough about how logging is implemented to even need to call that utility.

Interestingly, the presetGenerator is really the only one that needs file logging since the Nx harness is eating its console output. The other generators should probably explicitly not output to file, or if they do they need to put it somewhere predictably on system that is definitely not within the current workspace (again to avoid accidentally committing this file). All of these should be able to output to console normally, however.

One thought is to just always output generator logs to the directory adjacent to the generated workspace. This could be a little hidden, though, and probably isn't ideal.

chiubaka commented 2 years ago

I could output the logs to the tmp directory in the generated workspace. By default, this is already in the .gitignore file and was added there by Nx's workspace generator.

So far this is the idea I like the best.

chiubaka commented 2 years ago

Hmmm I had entirely forgotten, but @nrwl/devkit includes a logger. It's not clear to me where that logs to, though. If I cant figure out where that output goes for my preset generator, then this is almost certainly the right thing to be using rather than winston.

chiubaka commented 2 years ago

Alright, I looked through both the logger and output utils. As far as I can tell, they're both relatively simple / dumb. I can't find any obvious references to what might be file-based logging anywhere.

I think for now we're going to go ahead and keep winston. Perhaps in the long-term, it would be nice if console-based logging utilized the existing logger functionality for consistency, but that's a very minor thing. Created #72 to track that.