Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2004, 02:15 PM
maaltan
Fire Beetle
 
Join Date: May 2004
Posts: 9
Default Jr Dev Code - Error logging

i mentioned a need for error logging centralization in the bugs forum. well i got my laptop back and slapped together the following. it sets up the infrastructure for the above as well as an extendable "utility function" set. By using this, this allows you to quickly and easily change often performed tasks(logging, etc)


lets see if i can get this code in here before my session times out.

First I am going to paste two files needed to use this, util.h and util.c

util.h
Code:
// 
// UTIL.h

// Include this in any file you wish to use the utilities in.

#pragma once

#ifndef UTIL_INCLUDED //make sure that this header is only compiled once to prevent link errors
#define UTIL_INCLUDED

//return value termination constants
const int RET_ERROR = 666;
const int RET_NORMAL = 0;

//severity indexies 
const int MAX_SEVERITY = 4;

const int SEV_NULL = 0;  //probably not needed, more of a place holder
const int SEV_INFO = 1;  //Information only; nothing to be alarmed about
const int SEV_WARN = 2;  //Warning; Not critical, but should be looked at when time allows
const int SEV_ERRO = 3;  //ERROR; Big problem, normal program operation can continue 
						 //but bad things might happen
const int SEV_FATL = 4;  //FATAL ERROR; MAJOR ERROR, program operation cannot continue, 
						 //You should use this before terminating the server.

//If you expand the error messages make sure you add it to the array in util.cpp
//Tried putting array in header but vc++.net's linker didn't like it

//Function prototypes
int info_report(int severity, char *buf);

#endif
util.c
Code:
//util.c 
// Add this to your project along with the header to use these functions

#include "stdafx.h"
#include "util.h"
#include <time.h>

//severity label array 
const char* severity_lookup[] = {	{"Null"},
								{"info"},
								{"Warn"},
								{"ERRO"},
								{"FATL"} };


int info_report(int severity, char* error)
// return value as defined in util.h
{
	time_t timer;
	struct tm * curtime;
	
	if (severity > MAX_SEVERITY)
	{
		info_report(SEV_ERRO,"INVALID SEVERITY IN INFO_REPORT:  Please use valid severity value");
		return(RET_ERROR);
	} else
	{   
			timer=time(NULL);
			curtime = localtime(&timer);	

			printf( "%s[%.2d:%.2d:%.2d] %s\n" ,
					severity_lookup[severity],
					(*curtime).tm_hour,
					(*curtime).tm_min,
					(*curtime).tm_sec,
					error);
			
			return(RET_NORMAL);
	}
	return(RET_NORMAL);
}

Ok there it is. Its semi readable. I'm a bit rusty in c/c++ but this compiles in vc++.net . please let me know if you have problems with it and i will try to polish it.

Tto use the only (at the moment ) function in this file simply call it as follows:

info_report( severity , "Error string");

severity is defined as a number between 0 and 4. defined as constants as follows:

SEV_NULL=0 - unused, makes the numbers make more sense
SEV_INFO=1 - Information, nothing wrong, maybe a login
SEV_WARN=2 - Warning, minor problem
SEV_ERRO=3 - error, something broke but not critical
SEV_FATL=4 - severe error, server must terminate/restart

so for example, to log an error with the database and a character could not be loaded, but the server can continue, it would be used as follows

info_report(SEV_ERRO, "Error Loading Character, <enter reason here>");

THis can be edited and/or extended if need be. i think my comments explain how, let me know if you need clairification.

Well thats it i think.
Thanks for your time
Maaltan
Reply With Quote
  #2  
Old 05-25-2004, 02:19 PM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

This looks alot like an enterprise level logging model.. You don't happen to work in an IT industry do you?
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #3  
Old 05-25-2004, 02:24 PM
maaltan
Fire Beetle
 
Join Date: May 2004
Posts: 9
Default

used to, mostly just a hobby coder though. but the coms bombed and now I just code for fun.

thats not quite enterprise level, but it does lay the infrastructure for it though.

enterprise would probably involve fault tolerant databases and redundancy. which would be possibly. using this as a starting point you could, say, recode info_report to insert logs into a mysql table. or a log file.

This is nasty code. I would have probably been fired for this code, well not quite.
Reply With Quote
  #4  
Old 05-25-2004, 02:31 PM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

Now you just need to create a stand alone logging daemon process and you have a robust logging solution !
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #5  
Old 05-25-2004, 02:40 PM
maaltan
Fire Beetle
 
Join Date: May 2004
Posts: 9
Default

Hmmm, thats do-able. Would you prefer to use named pipe, UDP, or Process hook? but I digress, its unnecessary for at this stage of development though.

It would be of benifit in the future if people start running high volume persistant clustered servers.

do you know how to create patch files in visual c++? I will go through and replace all the errors with info_report calls and create a patch file that will allow you to quickly make the changes. i used to know how to do it in unix ..hmm . to GOOGLE.
Reply With Quote
  #6  
Old 05-25-2004, 07:04 PM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default

Now THIS is the kind of code we are looking for, or examples of things you have done with the emulator code. It needs to show skill, knowledge and competence.
__________________
++[>++++++<-]>[<++++++>-]<.>++++[>+++++<-]>[<
+++++>-]<+.+++++++..+++.>>+++++[<++++++>-]<+
+.<<+++++++++++++++.>.+++.------.--------.>+.
Reply With Quote
  #7  
Old 05-27-2004, 12:37 PM
maaltan
Fire Beetle
 
Join Date: May 2004
Posts: 9
Default total recall

ok i got bored so i learned how to use variable parameters. here is the updated util.cpp file

This update will let you use this exactly like printf. for example:

Code:
opcode = 55;
info_report(SEV_WARN,"Unknown opcode: %d", opcode);
will print:

Code:
Warn [20:33:18] Unknown opcode: 55
all of printf's codes should work. Please let me know if wierdness happens. this is new ground for me.

Code:
#include "stdafx.h"
#include "util.h"
#include <time.h>
#include <stdarg.h>

//severity label array 
const char* severity_lookup[] = {	{"Null"},
								{"info"},
								{"Warn"},
								{"ERRO"},
								{"FATL"} };


int info_report(int severity, char* error, ...)
// return value as defined in util.h
{
	time_t timer;
	struct tm * curtime;

	if (severity > MAX_SEVERITY)
	{
		info_report(SEV_ERRO,"INVALID SEVERITY IN INFO_REPORT:  Please use valid severity value");
		return(RET_ERROR);
	} else
	{   
			// setup for variable argument list
			va_list arglist;
			va_start(arglist, error);
			//end setup

			timer=time(NULL);
			curtime = localtime(&timer);

			printf( "%s[%.2d:%.2d:%.2d] " ,
					severity_lookup[severity],
					(*curtime).tm_hour,
					(*curtime).tm_min,
					(*curtime).tm_sec);

			vprintf( error,arglist); //its maaaaagic

			printf("\n");
                                                va_end(arglist); //close the list up
			return(RET_NORMAL);
	}
	return(RET_NORMAL);
}
you will need to change the function prototype in util.h from:

int info_report(int severity, char* error);

to

int info_report(int severity, char* error, ...);
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 08:19 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3