Skip to content

tralf-strues/log-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple but convenient log generator

This is a simple html log generator. See examples below to better understand how it works or documentation where you can find out what each function does.

Example 1 (Hello World)

#include "log_generator.h"

int main()
{
    LG_Init(); // initializes log file
    
    LG_Write("Hello, World!");
    
    LG_Close(); // closes log file
    
    return 0;
}

This code will produce the following log.html file:

<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="log.css"></head>
<body>
Hello, World!
</body>
</html>

How log.css could be used you can find in example 3.

Example 2 (Adding color 🎨)

#include "log_generator.h"

enum Error
{
	NO_ERROR,
	ERROR_CODE_1,
	ERROR_CODE_2,
	ERROR_CODE_3,
	ERROR_CODE_4
};

int main()
{
	Error status = NO_ERROR;
	
	/* ... something bad happened */
	status = ERROR_CODE_2;
	
	if (status != NO_ERROR)
	{
		LG_Init(); 
    
		// starts an error message with red color
		LG_WriteMessageStart(LG_COLOR_RED);
		
		LG_Write("An ERROR occurred!\n");
		
		// works similar to printf(...)
		LG_Write("Error code is %d\n", status); 
		
		// ends the error message
		LG_WriteMessageEnd();
		
		LG_Close(); 
    }
	
    return 0;
}

This code will produce the following log.html file:

<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="log.css"></head>
<body>

<pre style="color: rgb(255, 0, 0);">
An ERROR occurred!
Error code is 2

</pre>

</body>
</html>

Example 3 (Adding CSS classes)

You can also use CSS classes. The default log.css file can be found here. You can edit it and add your own classes to your liking, or change the default values if you wish.

#include "log_generator.h"

enum Error
{
	NO_ERROR,
	ERROR_CODE_1,
	ERROR_CODE_2,
	ERROR_CODE_3,
	ERROR_CODE_4
};

int main()
{
	Error status = NO_ERROR;
	
	/* ... something bad happened */
	status = ERROR_CODE_2;
	
	if (status != NO_ERROR)
	{
		LG_Init(); 
    
		// starts an error message with error style class
		LG_WriteMessageStart(LG_STYLE_CLASS_ERROR);
		
		LG_Write("An ERROR occurred!\n");
		LG_Write("Error code is %d\n", status); 
		
		LG_WriteMessageEnd();
		
		LG_Close(); 
    }
	
    return 0;
}

This code will produce the following log.html file:

<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="log.css"></head>
<body>

<pre class="LG_ERROR">
An ERROR occurred!
Error code is 2

</pre>

</body>
</html>

About

An attempt to create a convenient logging library in C.

Topics

Resources

Stars

Watchers

Forks