Comments (13)
Currently, I'm piggy backing off of the same mailing list as the Logback
users list ([email protected]).
Do you have a specific question? I might be able to help you directly.
-Tony
On Tue, Nov 1, 2011 at 6:02 PM, Fred Eisele <
[email protected]>wrote:
Which forums/mailing lists should be used for questions regarding proper
use of logback for android?Reply to this email directly or view it on GitHub:
#1
from logback-android.
Tony,
Yes I have a specific question.
When should the configuration file be processed?
In the example ( https://github.com/tony19/logback-android ) you
show an Activity opening and parsing the configuration file.
Doing this for every activity would be be quite a bit of overhead.
I'm guessing that the configuration only needs to be done once per
{thread, process, application}?
I have been using slf4j so I was able to drop logback-android in with no
changes.
I am looking for some guidance on the best way to deal with the
configuration file.
Thanks
Fred
On Tue, Nov 1, 2011 at 5:09 PM, Tony Trinh <
[email protected]>wrote:
Currently, I'm piggy backing off of the same mailing list as the Logback
users list ([email protected]).Do you have a specific question? I might be able to help you directly.
-Tony
On Tue, Nov 1, 2011 at 6:02 PM, Fred Eisele <
[email protected]>wrote:Which forums/mailing lists should be used for questions regarding proper
use of logback for android?Reply to this email directly or view it on GitHub:
#1Reply to this email directly or view it on GitHub:
#1 (comment)
"For a successful technology, reality must take precedence over public
relations, for nature cannot be fooled." --Feynman
"It's not nice to fool Mother Nature" --Mother Nature
from logback-android.
I have code that looks like this...
public class Subscribe extends ActivityEx implements OnClickListener {
private static final Logger logger = LoggerFactory.getLogger("my-api-d");
...
public class AmmoService extends Service implements
OnSharedPreferenceChangeListener {
private static final Logger logger = LoggerFactory.getLogger("my-service");
...
You get the idea.
from logback-android.
That's correct. The configuration only needs to be done once per
application and does not need to be done per Activity. If you have
multiple Activities in your application, then I recommend a separate class
(singleton) to manage the Logback initialization (invoke the
JoranConfigurator). The singleton would be shared among your Activities.
But upcoming changes would obviate the need for any code-based
configuration...
I'm actually in the process (actually, it's rather stop-and-go due to other
priorities) of updating logback-android to leverage AndroidManfiest.xml for
Logback configuration and/or specifying search paths for config files.
If you can't wait for my changes, another way to remove code-based
configuration is to insert your Logback config file (logback.xml or
logback-test.xml) into the root of your apk file (which is simply a ZIP
fle).
On Tue, Nov 1, 2011 at 6:22 PM, Fred Eisele <
[email protected]>wrote:
Tony,
Yes I have a specific question.
When should the configuration file be processed?In the example ( https://github.com/tony19/logback-android ) you
show an Activity opening and parsing the configuration file.
Doing this for every activity would be be quite a bit of overhead.
I'm guessing that the configuration only needs to be done once per
{thread, process, application}?
I have been using slf4j so I was able to drop logback-android in with no
changes.
I am looking for some guidance on the best way to deal with the
configuration file.
ThanksFred
On Tue, Nov 1, 2011 at 5:09 PM, Tony Trinh <
[email protected]>wrote:Currently, I'm piggy backing off of the same mailing list as the Logback
users list ([email protected]).Do you have a specific question? I might be able to help you directly.
-Tony
On Tue, Nov 1, 2011 at 6:02 PM, Fred Eisele <
[email protected]>wrote:Which forums/mailing lists should be used for questions regarding
proper
use of logback for android?Reply to this email directly or view it on GitHub:
#1Reply to this email directly or view it on GitHub:
#1 (comment)"For a successful technology, reality must take precedence over public
relations, for nature cannot be fooled." --Feynman
"It's not nice to fool Mother Nature" --Mother NatureReply to this email directly or view it on GitHub:
#1 (comment)
from logback-android.
To answer your question, code-based Logback initialization should be done as early as possible (before you call the Logger
). Otherwise, the BasicConfigurator
will take effect, printing your log statements to stdout (logcat).
from logback-android.
The following fragment seems to do what I want.
Eventually, there will be an activity to control the logger but the application can get an initial configuration loaded.
public class ApplicationEx extends Application {
private static final Logger logger = LoggerFactory.getLogger(ApplicationEx.class);
private static ApplicationEx singleton;
public ApplicationEx() {
super();
}
public static ApplicationEx getInstance() {
return singleton;
}
@Override
public final void onCreate() {
super.onCreate();
logger.debug("::onCreate");
singleton = this;
configure(this.getApplicationContext());
}
}
public static void configure(Context context) {
final InputStream inputStream;
final File configDir = context.getDir("logger", Context.MODE_WORLD_READABLE);
final File configFile = new File(configDir, "logger.xml");
Toast.makeText(context, configFile.toString(), Toast.LENGTH_LONG).show();
final File globalConfigFile = new File(Environment.getDataDirectory(), "logger.xml");
if (configFile.exists()) {
try {
inputStream = new FileInputStream(configFile);
} catch (FileNotFoundException ex) {
//logger.error("no policy file {} {}", configFile, ex.getStackTrace());
return;
}
} else if (globalConfigFile.exists()) {
try {
inputStream = new FileInputStream(globalConfigFile);
} catch (FileNotFoundException ex) {
//logger.error("no policy file {} {}", globalConfigFile, ex.getStackTrace());
return;
}
}
else {
// Toast.makeText(context, R.string.no_log_config_file, Toast.LENGTH_LONG).show();
try {
final InputStream default_config = context.getResources().openRawResource(R.raw.default_logger);
final OutputStream out = new FileOutputStream(configFile);
final byte[] buf = new byte[1024];
int len;
while ((len = default_config.read(buf)) > 0) {
out.write(buf, 0, len);
}
default_config.close();
out.close();
} catch (NotFoundException ex) {
//logger.error("asset not available {}", ex.getMessage());
} catch (FileNotFoundException ex) {
//logger.error("file not available {}", ex.getMessage());
} catch (IOException ex) {
//logger.error("file not writable {}", ex.getMessage());
}
inputStream = context.getResources().openRawResource(R.raw.default_logger);
}
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
final JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(inputStream);
} catch (JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
Of course this configure method could be moved to a logging specific class.
from logback-android.
I notice in the logback documentation ...
"Specifying the location of the default configuration file as a system property
"If you wish, you can specify the location of the default configuration file with a system property named logback.configurationFile. The value of this property can be a URL, a resource on the class path or a path to a file external to the application.
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
"
I would like to be able to do this with android.
Maybe something like...
adb shell setprop logback.config.file logger.xml
Along the line of the config method mentioned above this would check for logger configuration files.
/sdcard/logger.xml and /data/data/<blah.app>/app_logger/logger.xml
or something like that.
from logback-android.
I had started looking into this a while ago. AFAIK, Android doesn't provide a means of reading the properties set from adb shell setprop
. Those are system-level properties as opposed to process-level ones that can be read by System.getProperty
. Someone discovered hidden functions for this, but I'm hesitant to use something unsupported (not guaranteed to exist on the next Android release).
from logback-android.
I found this...
http://www.google.com/codesearch#2wSbThBwwIw/libcutils/properties.c&q=property_get%20package:android&type=cs
...and this...
http://rxwen.blogspot.com/2010/01/android-property-system.html
Sounds like the property_get() and property_set() are not part of the ndk but used widely
while, as you said, System.getProperty() is something completely different.
(Although it may be initialized from the native properties, but it would be unreliable if it works at all.)
It looks like property_get() is exposed through SystemProperties...
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2.1_r1/android/os/SystemProperties.java#SystemProperties
...which shows up in jni as...
http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/jni/android_os_SystemProperties.cpp&ct=rc&cd=36&exact_package=android&q=package:android%20lang:%5Ec%2B%2B$%20property_get&sq=
But this is a hidden class.
Nevertheless, it can be accessed via reflection...
http://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties
...or a jni could be written.
Or on a different tack, we could presume a file in a standard location such as the data directory...
http://developer.android.com/reference/android/os/Environment.html#getDataDirectory()
/data/data/logback.xml
...for example.
In any case I think the default should be to use the LogcatAppender rather than StdOut.
What do you think?
from logback-android.
I'm already working on a way to load the configuration file (or its search path). I'll probably have time for it in a few weeks.
You might be right about LogcatAppender
.
from logback-android.
Anything I can do to help?
from logback-android.
Thanks, I could certainly use some help, but the configuration file stuff is still on hold for now. I'll keep you posted.
LogcatAppender
is now the default. commit fa6c20b
from logback-android.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from logback-android.
Related Issues (20)
- Document usage compatible with the standard JUnit tests
- write log after app killed ,how to write log real time HOT 1
- Log file is not creating at very first time when app gets launched in android. HOT 5
- No log is printed with Slf4j 2.x.x HOT 10
- Missing SSL parameter configuration HOT 1
- Dependency Dashboard
- how to rename locback.xml as logback-demo.xml HOT 1
- Caused by java.lang.NullPointerException Attempt to invoke interface method 'void androidx.appcompat.view.menu.d.u(int)' on a null object reference HOT 1
- ArrayIndexOutOfBoundsException on Android 10
- LogcatAppender show errors for logs' "highlighting".
- Lazy setting does not work
- Can't Create Logger: DateTokenConverter not found? HOT 2
- The log cannot be written correctly in the case of multi-process Android application? HOT 2
- Cannot create AAR with ./scripts/makejar.sh HOT 1
- Excepton in kotlin app with jetpack compose, only in release mode HOT 1
- Missing transitive dependency on slf4j-api-2.x
- The release version turns on minifyEnabled, and the file name is printed as null. <pattern>[%date] [%file:%line] - %msg%n</pattern>
- logback-android and logback-classic ILoggingEvent binary incompatibility getMarkers vs getMarkerList HOT 1
- can not write to the file that under the android getExternalFilesDir()
- App death during rollover causes losing logs and malformed gz files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logback-android.