473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Logger Object

Hi,

This is my first post, and I got questions about logging.
When something happen within an object, and if I would like to log the event, what would be a good way to do it?

1. I make the logger object embedded in the class and use it (as the one below)
2. I have only one logger that other objects can call. Create Logger once, and let it stay there where other objects can call for services.

The reason I asked this question about this because I've been reading some concept about AOP, which mentioned an example on the logging extensively. The question above is not related to the AOP(haven't got that far yet). I've just wondered why people embedded the logger in the class.


What would be good practices to create logger objects?
What would be an effect if I inherit the based class that contains the logger object?

public class P {
private int count;
Logger loggerObject;

P( ) {
count = 0;
loggerObject = new Logger();
}

public void putCount(int i) {
loggerObject.writeLog("Changed count from" + count + " to " +
i);
count = i;
}

public int getCount() {
return count;
}
}

This code I modified from the book.
Jan 2 '07 #1
1 1558
r035198x
13,262 8TB
Hi,

This is my first post, and I got questions about logging.
When something happen within an object, and if I would like to log the event, what would be a good way to do it?

1. I make the logger object embedded in the class and use it (as the one below)
2. I have only one logger that other objects can call. Create Logger once, and let it stay there where other objects can call for services.

The reason I asked this question about this because I've been reading some concept about AOP, which mentioned an example on the logging extensively. The question above is not related to the AOP(haven't got that far yet). I've just wondered why people embedded the logger in the class.


What would be good practices to create logger objects?
What would be an effect if I inherit the based class that contains the logger object?

public class P {
private int count;
Logger loggerObject;

P( ) {
count = 0;
loggerObject = new Logger();
}

public void putCount(int i) {
loggerObject.writeLog("Changed count from" + count + " to " +
i);
count = i;
}

public int getCount() {
return count;
}
}

This code I modified from the book.
Yeah the design could be argued a lot. I'd personaly prefer a logger that has static methods and so I'd not have to include the logger object in my design.
Jan 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nermin Brgulja | last post by:
Hi, I am using jdk1.4 Logger with a FileHandler for logging in a web application, and have two questions regarding logging: The first question is: I've created an Logger and mapped it to an...
0
by: Laszlo | last post by:
Hi I need a GL::Logger wich implements Class::Singleton to be a singleton and Log::Log4perl to can log amy message into a file. Here is the module source:...
10
by: Gary Jefferson | last post by:
Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B', and each module has its own logger, created with: module1logger = logging.getLogger('project.A') and module2logger =...
5
by: CedricCicada | last post by:
Greetings! I want to write messages into the Windows event log. I found sevicemanager, but the source is always "Python Service", and I'd like to be a bit more descriptive. Poking around on...
4
by: garyjefferson123 | last post by:
Suppose I have some sort of context variable that I want to appear in log messages. E.g.: logger = logging.getLogger("somelogger") class SomeOp: def __init__(self, ctx): self.ctx = ctx def...
2
by: DwBear75 | last post by:
I am hoping to find some simple examples of how to create a logger instance using smtphandler. I don't want to create a separate ini file. I just want to sent the smtphost, from, to right in the...
0
by: Dr. Colombes | last post by:
I've used a very nice Keystroke Logger Python shareware program (EVDEV.py), written by Micah Dowty. But I couldn't find a dedicated ASCII Character Logger program. Does anyone know of an ASCII...
1
by: nagk9 | last post by:
Hi , I am using log4j in my application. I have the problem with log4j.properties file . It will automatically appends another logger file from the current logger which i am using for the...
1
by: Matimus | last post by:
Yes but in the other hand :http://docs.python.org/library/logging.html#logger-objects That is part of the power of the logging module. If you ask for a logger of the same name in two different...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.