is it possible to create log file for each country

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 !
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?
 
garypfirstechConnect With a Mentor Commented:
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
 
CEHJCommented:
How do you deploy it?
0
 
Sathish David Kumar NArchitectAuthor Commented:
its single application only . connect with different schema for that country
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
garypfirstechCommented:
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
 
Sathish David Kumar NArchitectAuthor Commented:
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
 
garypfirstechCommented:
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
 
Sathish David Kumar NArchitectAuthor Commented:
>>>>>>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
 
Sathish David Kumar NArchitectAuthor Commented:
>>>>>>Logger myLogger = Logger.getLogger(countryNameObtainedFromSession + thisClass.class.getName());


is i want to declare anything in log4j.propety file
0
 
garypfirstechConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.