change log4j Logging level from INFO to DEBUG - java

In my java code, the following line
getHibernateTemplate().save(billingCompany);
is printing a logger message
2013-11-11 14:05:20,962 INFO [STDOUT] Hibernate: insert into
billing_log_company (COMPANY_ID, BILLING_LOG_ID) values (?, ?)
But actually I need DEBUG in place of INFO like this:
2013-11-11 14:05:20,962 DEBUG [STDOUT] Hibernate: insert into
billing_log_company (COMPANY_ID, BILLING_LOG_ID) values (?, ?)
I mean that we are not writing logger.info. logger.debug etc..
getHibernateTemplate().save(billingCompany) is printing that logger msg in INFO mode.

Hibernate messages it self is in hibernate source code, you can't change that. However, you can change Hibernate log level to warn or debug. but this will fill your console with a lot of logs
In your log properties file change
log4j.logger.org.hibernate=info
to
log4j.logger.org.hibernate=debug
or
log4j.logger.org.hibernate=warn

I don't understand your question. If you want DEBUG rather than INFO in the spring hibernate template then you'll have to change their source code. If you want to use DEBUG in our own code, just use
logger.debug(...)

Benjamin was clear in his approach.
You must be using some api to log like log4j, promatter...
most logger api has different methods for logging different scenarios.
Take log4j for example,
static Logger loggerfile = Logger.getLogger(ThisClass.class.getName());//creating logger instance
loggerFile.debug("debug");
loggerFile.info("info");
loggerFile.error("erre");

Related

How to fetch Execution time for hibernate Insert and Update SQL statements

We can able to fetch Hibernate SQL statements and their bind parameters But we need to fetch the elapsed time for those sql statements as well.
Already tried with below logs:
org.hibernate.SQL = debug
org.hibernate.type = trace
Also tried with statistics parameters in persistence.xml:
org.hibernate.stat = debug
It gaves only execution time for named queries not the other DMLs generated through em.persist.
Please let me know any logs parameters to fetch the round trip of all SQL statements execution time
we are using hibernate version 5.3.7

spring-boot-data-source-decorator with p6spy are not logging insert statements

I am using p6spy to log the sql statements.we are using springboot/hibernate for Java ORM mapping.I see only select statements are getting loggged in spy.log.when insert statemnets are executing in the code I see only commmit is coming in the log but insert statements are not coming.
|connection|commit||
|connection|statement | select * from emp_id where id=1234
https://github.com/gavlyukovskiy/spring-boot-data-source-decorator
# Register P6LogFactory to log JDBC events
decorator.datasource.p6spy.enable-logging=true
# Use com.p6spy.engine.spy.appender.MultiLineFormat instead of com.p6spy.engine.spy.appender.SingleLineFormat
decorator.datasource.p6spy.multiline=true
# Use logging for default listeners [slf4j, sysout, file, custom]
decorator.datasource.p6spy.logging=file
# Log file to use (only with logging=file)
decorator.datasource.p6spy.log-file=spy.log
# Class file to use (only with logging=custom). The class must implement com.p6spy.engine.spy.appender.FormattedLogger
decorator.datasource.p6spy.custom-appender-class=my.custom.LoggerClass
# Custom log format, if specified com.p6spy.engine.spy.appender.CustomLineFormat will be used with this log format
decorator.datasource.p6spy.log-format=
# Use regex pattern to filter log messages. If specified only matched messages will be logged.
decorator.datasource.p6spy.log-filter.pattern=
# Report the effective sql string (with '?' replaced with real values) to tracing systems.
# NOTE this setting does not affect the logging message.
decorator.datasource.p6spy.tracing.include-parameter-values=true

query.setLockMode("a",lockMode.upgrade_skiplocked) gives a warning in hibernate

I am trying to substitute my sql query that is for Oracle and it is as :
select trim(a.id) as id from tbl_insttype a where a.chi_city='1' order by cast(a.id as int) for update skip locked
Following is an equivalent hibernate substitution :
Query query=session.createQuery("select trim(a.id) as id from TblInsttype a where a.chiCity='1' order by cast(a.id as int) ");
query.setLockMode( "a",LockMode.UPGRADE);
but my log warns that
LOG:
12830 [main] DEBUG org.hibernate.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
12846 [main] WARN org.hibernate.dialect.function.TemplateRenderer - HHH000174: Function template anticipated 4 arguments, but 1 arguments encountered
12846 [main] DEBUG org.hibernate.hql.internal.ast.QueryTranslatorImpl - HQL: select trim(a.id) as id from com.imageinfo.eclear.cfg.xml.TblInsttype a where a.chiCity='1' order by cast(a.id as int)
12846 [main] DEBUG org.hibernate.hql.internal.ast.QueryTranslatorImpl - SQL: select trim(tblinsttyp0_.ID) as col_0_0_ from EXPOTDBU_PHILIPPINES.TBL_INSTTYPE tblinsttyp0_ where tblinsttyp0_.CHI_CITY='1' order by cast(tblinsttyp0_.ID as number(10,0))
12846 [main] DEBUG org.hibernate.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
12861 [main] WARN org.hibernate.loader.Loader - HHH000445: Alias-specific lock modes requested, which is not currently supported with follow-on locking; all acquired locks will be [UPGRADE]
12861 [main] WARN org.hibernate.loader.Loader - HHH000444: Encountered request for locking however dialect reports that database prefers locking be done in a separate select (follow-on locking); results will be locked after initial query executes
12877 [main] DEBUG org.hibernate.SQL - select trim(tblinsttyp0_.ID) as col_0_0_ from EXPOTDBU_PHILIPPINES.TBL_INSTTYPE tblinsttyp0_ where tblinsttyp0_.CHI_CITY='1' order by cast(tblinsttyp0_.ID as number(10,0))
Hibernate: select trim(tblinsttyp0_.ID) as col_0_0_ from EXPOTDBU_PHILIPPINES.TBL_INSTTYPE tblinsttyp0_ where tblinsttyp0_.CHI_CITY='1' order by cast(tblinsttyp0_.ID as number(10,0))
12861 says some clear words that i didnt get it right.and the sql query below it also doesnt have any for update skip locked in it.
I dont get what i am doing wrong,should i try some other things?
PLUS
it is giving the same error for different lockModes.
It says Alias-specific lock modes requested, which is not currently supported with follow-on locking, so I think you should try it without aliasing your table with a. (There is only one table, is it needed at all?)
Maybe the HQL parser not recoginze the alias, you have to change hql from select trim(a.id) as id from tbl_insttype a to
select a.id from tbl_insttype a .
I have tried the count(a.id) query does not support setLockMode, will throw could not locate alias to apply lock mode : a exception.
A simple select(a) from Entity a works.

how to run hive in debug mode

i took example from cloudera website to write a custom SerDe for parsing a file
http://blog.cloudera.com/blog/2012/12/how-to-use-a-serde-in-apache-hive/
it seems a good example but when i create table with custom serde
ADD JAR <path-to-hive-serdes-jar>;
CREATE EXTERNAL TABLE tweets (
id BIGINT,
created_at STRING,
source STRING,
favorited BOOLEAN,
retweeted_status STRUCT<
text:STRING,
user:STRUCT<screen_name:STRING,name:STRING>,
retweet_count:INT>,
entities STRUCT<
urls:ARRAY<STRUCT<expanded_url:STRING>>,
user_mentions:ARRAY<STRUCT<screen_name:STRING,name:STRING>>,
hashtags:ARRAY<STRUCT<text:STRING>>>,
text STRING,
user STRUCT<
screen_name:STRING,
name:STRING,
friends_count:INT,
followers_count:INT,
statuses_count:INT,
verified:BOOLEAN,
utc_offset:INT,
time_zone:STRING>,
in_reply_to_screen_name STRING
)
PARTITIONED BY (datehour INT)
ROW FORMAT SERDE 'com.cloudera.hive.serde.JSONSerDe'
LOCATION '/user/flume/tweets';
it executed perfectly fine but when i do
select * from tweets;
i am getting nothing so thats why i wanted to know if i can run hive in debug mode to see where it is getting failed
You better start hive shell by switching logger mode to DEBUG as follows, I hope you could find something useful from there.
hive --hiveconf hive.root.logger=DEBUG,console
Hive code can be debugged.This link may help you : https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide#DeveloperGuide-DebuggingHiveCode
Setting hive --hiveconf hive.root.logger=DEBUG,console may not always work because of company specific setup.
I ended up creating a hive-log4j.properties file in my home directory with following settings:
log4j.rootCategory=DEBUG,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n
and started hive shell using CLASSPATH=$HOME hive which adds your home directory having hive-log4j.properties in front of the classpath and so is picked up.

hibernate show_sql value

this is example of how sql is showed when using show_sql=true
Hibernate:
select
propertyse0_.entity_name as entity1_3_0_,
propertyse0_.entity_id as entity2_3_0_,
propertyse0_.entity_key as entity3_3_0_,
propertyse0_.key_type as key4_3_0_,
propertyse0_.boolean_val as boolean5_3_0_,
propertyse0_.double_val as double6_3_0_,
propertyse0_.string_val as string7_3_0_,
propertyse0_.long_val as long8_3_0_,
propertyse0_.int_val as int9_3_0_,
propertyse0_.date_val as date10_3_0_
from
OS_PROPERTYENTRY propertyse0_
where
propertyse0_.entity_name=?
and propertyse0_.entity_id=?
and propertyse0_.entity_key=?
possible to show value to gather with the sql rather than '?'
Set your logging leven to "TRACE".
In your log4j.properties (assuming your using Log4J):
log4j.logger.org.hibernate=TRACE
Will result in lots of logging tough...
You need to set up your logging framework to log this level of details. See here for the various loggers that Hibernate uses, and how to use them.
The particular one that you want is:
org.hibernate.type - Log all JDBC parameters
not directly. you can use log4jdbc to log all the data that is sent over jdbc. It has a logger that inlines the prepared statement values.

Categories