Skip to content

Conversation

@KevinKelly25
Copy link
Contributor

This PR adds logging via the winston package to routes/user.js. The file winston.js was added to create the logger and export it for ease of use. Winston is pretty flexible and can be customized in many ways. Because of that I am creating this PR as a baseline for discussion on how we want to format our logs.

The current format is as follows: Timestamp log-level: ( Route ) User: {username} info-message
An example: 2019-08-23T20:52:27.151Z info: (Change-Password) User: teststu2 attempting to change password

There is two log files combined.log and error.log. The combined.log has all logs and error.log contains only the error level logs.

Currently, everything that results in .error after the database query is getting put into error log level but in another PR we will be expanding the error functionality to handle different types of errors in different ways. For example, if the username was incorrect and it fails the query because of that it will be logged in info not error. error should likely only be used for server errors or uncaught errors.

@KevinKelly25
Copy link
Contributor Author

In the latest commit I added more verbose error logging in this PR instead of another. I decided they were related enough to include in this PR and save time. Using the various error codes that can happen I created a switch statement that populates messages for the user/log based on error code. If there is no matching error code that means it was either an unhandled error or a server error.

One thing I forgot to mention in the original message. The timestamp in the error message is GMT. Do we want to use GMT or EST?

@smurthys
Copy link
Member

Excellent work @KevinKelly25. Please review my suggestions.

@smurthys
Copy link
Member

Yes, UTC is the correct time zone to use.

@KevinKelly25
Copy link
Contributor Author

The latest commits should resolve all outstanding comments. Thank you @smurthys for reviewing my work and making suggestions.

@KevinKelly25
Copy link
Contributor Author

The latest commit makes it so the path to where logs are created can be added via an environmental variable. To achieve this I added the module dotenv. This module takes the variables from a .env file and stores them in process.env. The .env file is ignored in git, as the environmental variable values are unique to each server instance.

In order to get this latest commit to work you will need to create a file .env in the src directory. In that file the following line should be there: PATH_TO_LOGS={path to where the logs are generated}

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

Successfully merging this pull request may close these issues.

3 participants