Link to home
Start Free TrialLog in
Avatar of ramnars
ramnars

asked on

logging data

In my processing function, depending upon the activity code , we do some processing  for different activities .  We need to implement logging now. Depending upon the activity code, the data that needs to log would vary.
for ex activity code 01 , log field 1 and field 2
for activity code 02, log field 2 and field 5.

I need some ideas to implement this logging mechanism.

Is it best to have a base logging class and then derive classes out of it for each and every activity code . the derived classes would have data members specific to what it needs to log and a overridenn method persistlog in all the classes would write all of its data members to the disk.

is there any design pattern examples / code that accomplishes some thing like this ?


Thanks for ur help
Avatar of rajeev_devin
rajeev_devin

>> is there any design pattern examples / code that accomplishes some thing like this ?
Most of the logger code I have gone so far is singleton class. That is, they will have only one object.
ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You need to modify the code to match your requirement.
Avatar of ramnars

ASKER

ok. the thing is depending upon the activity code ( there could be  more than 5) , the data that i need to log differs. shoudl i handle that scenario by testing for the activity codes ? I want it to be flexible enough to be modified in the future , in terms of logging data for a new activity code and also in terms of introducing new fields to the data that is being logged.

should i handle all the if conditions in the code where i invoke the logger ? i guess not.

so thats why i was leaning for the idea for invidiual classes for the activity codes and let them decide which fields they want to log


>> should i handle all the if conditions in the code where i invoke the logger ? i guess not.
As I told you need to extend the logger as per your requirement.

>> so thats why i was leaning for the idea for invidiual classes for the activity codes and let them decide which fields >> they want to log
If you extend the base class into number of derived classes. Your derived classes won't have much work to do.
So, what's the use of extending them.
The code I posted is not the complete solution for you. You need to extend it.
SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial