[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

is it possible to create log file for each country

Posted on 2011-05-10
9
Medium Priority
?
250 Views
Last Modified: 2012-05-11
Hi i have deployed my applciation for 22 country with one server . i am using log4j for logging

i need to create for each country is that possible ? like i am connection to DB schema !
0
Comment
  • 4
  • 4
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35729905
How do you deploy it?
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35731190
its single application only . connect with different schema for that country
0
 
LVL 7

Expert Comment

by:garypfirstech
ID: 35731453
There are many ways to do this.  I guess what you're talking about is a separate Logger for each country.  It depends on how you're instantiating the class so the issue here is in the details and it's hard to give a general answer without knowing more details about your application.

For example, if you instantiate a separate instance of a class for each country, you could make the Logger a field in the instance (as opposed to the usual practice of a static field in the class itself). Then, you could make the name of your Logger in your programs have the name of the country included in the Logger name, eg

Logger myLogger = Logger.getLogger(countryName + thisClass.class.getName());

So each instance of thisClass would have the appropriate logger.  Then you could issue your log requests in the usual way and have them go to separate appenders based on the logger name.

If this solution is not appropriate, perhaps you could provide more details about how you're connecting to a different schema for each country.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35746519
Actully how my application is work is !

when user login time i connect to admin schema and check the user deatils after that get country and his  schema so after that user transcation are coming with that country schema only !

eg:

I am sathish belonging to india so it will connected to india schema . like wise i want to create log file for each country  ?

how can i do that  ?
0
 
LVL 7

Expert Comment

by:garypfirstech
ID: 35746605
And how do you keep track of which schema to connect to when you need it later in the session?  Where is that information stored?  Do you instantiate a separate instance of each class for each user with the schema stored in that instance?
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35748438
>>>>>>And how do you keep track of which schema to connect to when you need it later in the session?  Where is that information stored?  

i put it session and used it.

>>>>Do you instantiate a separate instance of each class for each user with the schema stored in that instance?


i am not getting ur point
0
 
LVL 7

Accepted Solution

by:
garypfirstech earned 2000 total points
ID: 35748505
I was trying to understand how the schema name that you stored got used -- do you just dynamically build queries using the schema as a prefix whenever you need it or do you store the database connection and set the default schema as appropriate or what?

I guess I'd return to my original recommendation.  Whenever you create a Logger for an instance, just do it as:

  Logger myLogger = Logger.getLogger(countryNameObtainedFromSession + thisClass.class.getName());

This will give you a separate Logger for each country.  myLogger would be stored as a field in each class instance.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35748542
>>>>>>Logger myLogger = Logger.getLogger(countryNameObtainedFromSession + thisClass.class.getName());


is i want to declare anything in log4j.propety file
0
 
LVL 7

Assisted Solution

by:garypfirstech
garypfirstech earned 2000 total points
ID: 35748622
In your log4j.properties file, you can create a separate log file for each country like this:

log4j.logger.countryName = appenderName

Since each of your logger starts with the appropriate country name, this specification will be applied to all of the loggers for a particular country.

You'll need a separate appender for each country so that you can specify the appropriate file name for that country.  You might also want to consider initializing log4j programmatically if you have a large number of countries.  Or, you could just put all of the entries in the log4j.properties file.

Gary
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question