Skip to content

robert-fahey/log_guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LogGuard - Your Log Contract Guardian

LogGuard is a contract testing tool for validating the log codes generated by your application. It uses a YAML contract, a plain, human-readable file, that describes all the log codes your application should generate, including their severity level and a brief description.

Prerequisites

Before running LogGuard, make sure you have set up the LOG_CODES_YAML environment variable pointing to the path of your log_codes.yaml file.

You can set this up in Unix systems using the export command:

export LOG_CODES_YAML=/path/to/your/log_codes.yaml

Or in Windows using the set command:

set LOG_CODES_YAML=/path/to/your/log_codes.yaml

Coverage Checker - Log Code Coverage Validation

Coverage Checker is a tool that ensures your application logs cover all the log codes defined in the YAML contract. It calculates the percentage of log codes that are covered and logs the uncovered log codes.

Usage

  1. Create the YAML file (log_codes.yaml) at the root of your project.

  2. Make sure your application logs are in JSON format and include a Code field that corresponds to the code field in your YAML contract. Pipe these logs into Coverage Checker.

  3. Run the Coverage Checker using the following command:

cat ./app.log | go run ./cmd/coverage | tee coverage_report.txt

This will output a coverage report, including the log codes that are not covered by your application logs, and write it to coverage_report.txt.

Testing

To test the Coverage Checker, you can run:

go test ./cmd/coverage

Structure of the Code

Coverage Checker reads the log_codes.yaml file and the application logs from the standard input. For each log code, it checks whether a corresponding log entry exists.

The getLogCodesFromYaml() function reads and parses the log_codes.yaml file to get a list of log codes.

The getLogsFromStdin() function reads the application logs from the standard input, parses each log entry to extract the Code, and returns a list of these codes.

In the main() function, the coverage is checked by comparing the list of log codes from the YAML file and the list of log codes from the application logs. The function logs any log code not covered by the application logs and calculates the coverage percentage.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published