What a community. Let's see if someone gives me a hand in this. I happen to be working on organizing the repetitive and reusable codes in a library of my own and the intention is to distribute it in the factory in jar format as is normal. Everything is fine but I have a particular case with one of the classes that I am migrating; I have a class that is responsible for writing a series of reports of user activities of the system (a kind of monitoring), what I want to do is the following: make the name (among other things) of the logs file configurable, I thought about taking this configuration from a json file that is located in the assets of the project of whoever uses the library, not in the assets of the library.
EDIT: I edit my question so that it is better understood
In each each class that must register use events, an instance of the monitor is done in the following way:
public class MainActivity extends Activity {
Logit logger = Logit.getInstance(this.getClass());
...// onCreate(), etc ...
}
The instance is made even from classes that do not extend from Activity, for example from a SQLite DataBaseHelper.
The constructor of the Logit class is the following:
public static Logit getInstance(Class<?> clazz) {
if (log == null)
log = new Logit();
try {
AssetManager manager = Resources.getSystem().getAssets();
InputStream is = manager.open("logit.cfg");
String input = new Scanner(is, "UTF-8").useDelimiter("\A").next();
JSONObject json = new JSONObject(input);
String file = json.getString("filename");
boolean showv = json.getBoolean("showAppVersion");
log.setFileName(file);
log.setShowVersion(showv);
log.setClassName(clazz.getCanonicalName());
return log;
}catch(Exception e) {
log.write(Logit.stringStackTrace(e));
return log;
}
}
What interests me is to keep the argument really necessary at the time of the instance ( Class<?>
) and the location of the line of the instance is not feasible to locate references to AssetManager
of the host app to locate the resource , that's why my interest in finding a way to locate the repeatable configuration silently through a configuration file.
The question is how can I from the library take a configuration that exists in the project that uses the library, specifically the assets? I do not like the idea that the developer has to open the jar to modify the settings to his liking. A clear example of the goal is to emulate a configuration like that of log4j.
Greetings to all!