j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 366 forks source link

How to ignore ormlite logs? #113

Closed me73123 closed 3 years ago

me73123 commented 5 years ago

I get a lot of SQL logs with ormlite version 5.1. In the 4.4 version, there is no such log. But I will also use LoggerFactory.getLogger() in my project. How can I hide only the log of ormlite?

Logs like this:

D/com.j256.ormlite.stmt.StatementExecutor: 43, query-for-first of 'SELECT * FROM `profileimg` WHERE `owneruuid` = 'aabbcc' ' returned at 0 results
D/com.j256.ormlite.stmt.StatementBuilder: 43, built statement SELECT * FROM `profileimg` WHERE `owneruuid` = 'aabbcc' 
D/com.j256.ormlite.stmt.mapped.BaseMappedStatement: 43, prepared statement 'SELECT * FROM `profileimg` WHERE `owneruuid` = 'aabbcc' ' with 0 args
j256 commented 5 years ago

Which LoggerFactory is that? com.j256.ormlite.logger.LoggerFactory? Then it depends on which Logger you are using. My LocalLog allows you to set the system property com.j256.ormlite.logger.level to something like WARN to turn off those logs. There is also the /ormliteLocalLog.properties file which sets the levels per package. See the javadocs. With the property, you need to do this as soon as possible in your main or launching class. What is missing is a LocalLog.setGlobalLevel(...) method. I'll add it.

If you are using another logging system (like log4j, slf4j, etc.) then you'll need to figure out how they are configured.

me73123 commented 5 years ago

I tried the System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "ERROR") or System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "error") setting but it didn't work.Can you give me an example? Also, if I want to use ormliteLocalLog.properties to set, where should the file be placed in the project?

j256 commented 3 years ago

In 5.2 I added a Logger.setGlobalLogLevel(...) method which can be called early in your application to disable (or tune the level) of all logs. I also added an OFF level to be able to turn off log messages.

I've just added a NullLog log implementation as well that will be in 5.4. See: https://github.com/j256/ormlite-core/commit/e0103eed441ff4fe74b15805e4013896c2ba4853 Hope this is enough.