Month: March 2016

how to see where the log is ? Logger in slf4j,

Logger in slf4j, could you explain and give explain on how to use it? (e.g. how to see where the log is)

 

 

So  Like any  logger library  we have a configuration file where we place the locationof logs  it can be DB text file Console out put  DEbugger on statments

 

 

 

Logger in slf4j, could you explain and give explain on how to use it? (e.g. how to see where the log is)

 

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

private final Logger log = LoggerFactory.getLogger(getClass());

log.info(ex.getMessage());

 

 

Using slf4j with Simple logger

Create a Maven based project and this in your pom.xml.

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-api</artifactId>

<version>1.7.5</version>

</dependency>

Now you may use Logger in your Java code like this.

package deng;

import org.slf4j.*;

public class Hello {

static Logger LOGGER = LoggerFactory.getLogger(Hello.class);

public static void main(String[] args) {

for (int i = 0; i < 10; i++)

if (i % 2 == 0)

LOGGER.info(“Hello {}”, i);

else

LOGGER.debug(“I am on index {}”, i);

}

}

The above will get your program compiled, but when you run it, you will see these output.

bash> java deng.Hello

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

What it’s saying is that at runtime, you are missing the logging “implementation” (or the logger binding), so slf4j simply use a “NOP” implmentation, which does nothing. In order to see the output properly, you may try use an simple implementation that does not require any configuration at all! Just go back to your pom.xml and add the following:

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-simple</artifactId>

<version>1.7.5</version>

</dependency>

Now you see logging output on STDOUT with INFO level. This simple logger will default show any INFO level message or higher. In order to see DEBUG messages, you would need to pass in this System Property -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG at your Java startup.

Using slf4j with Log4j logger

Now we can experiment and swap different logger implementations, but your application code can remain the same. All we need is to replace slf4j-simple with another popular logger implementation, such as the Log4j.

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-log4j12</artifactId>

<version>1.7.5</version>

</dependency>

Again, we must configure logging per implementation that we picked. In this case, we need an

src/main/resources/log4j.properties file.

log4j.rootLogger=DEBUG, STDOUT

log4j.logger.deng=INFO

log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender

log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout

log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) – %m%n

src/main/resources/log4j.properties file for  writing into file  and stdout

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\logging.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
 
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

 

 

 

Re-run your program, and you should see similar output.

Using slf4j with JDK logger

The JDK actually comes with a logger package, and you can replace pom.xml with this logger implementation.

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-jdk14</artifactId>

<version>1.7.5</version>

</dependency>

Now the configuration for JDK logging is a bit difficult to work with. Not only need a config file, such as src/main/resources/logging.properties, but you would also need to add a System properties -Djava.util.logging.config.file=logging.properties in order to have it pick it up. Here is an example to get you started:

 

.level=INFO

handlers=java.util.logging.ConsoleHandler

java.util.logging.ConsoleHandler.level=FINEST

deng.level=FINEST

Using slf4j with Logback logger

The logback logger implementation is a super dupa quality implementation. If you intend to write serious code that go into production, you may want to evaluate this option. Again modify your pom.xml to replace with this:

<dependency>

<groupId>ch.qos.logback</groupId>

<artifactId>logback-classic</artifactId>

<version>1.0.13</version>

</dependency>

Here is a sample of configuration src/main/resources/logback.xml to get things started.

<configuration>

<appender name=”STDOUT” class=”ch.qos.logback.core.ConsoleAppender”>

<encoder>

<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} – %msg%n</pattern>

</encoder>

</appender>

 

<logger name=”deng” level=”DEBUG”/>

 

<root level=”INFO”>

<appender-ref ref=”STDOUT” />

</root>

</configuration>

 

 

for db logging

with

slf4j-api-1.7.5.jar

The next step was to change logback.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
            </pattern>
        </encoder>
    </appender>
    <appender name="db" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource
            class="ch.qos.logback.core.db.DriverManagerConnectionSource">
            <driverClass>org.postgresql.Driver</driverClass>
            <url>jdbc:postgresql://localhost:5432/simple</url>
            <user>postgres</user>
            <password>root</password> <!-- no password -->
        </connectionSource>
    </appender>

    <!-- the level of the root level is set to DEBUG by default. -->
    <root level="TRACE">
        <appender-ref ref="stdout" />
        <appender-ref ref="db" />
    </root>
</configuration>

As seen here, I have created two appenders – a console appender and a database appender.
The database appender here requires the JDBC driver, the jdbc url and the db credentials. An additional property is the connectionSource which is actually the type of Connection wrapper that we would like to use. Logback provides a few options here and I went with the DriverManagerConnectionSource class.
The next step was to write a test class to test the code:

public class SampleTestDbAppender {

   private static final Logger logger = LoggerFactory.getLogger(TestDbAppender.class);

   public  SampleTestDbAppender () {

 logger.info("Class instance created at {}",  DateFormat.getInstance().format(new Date()));
   }

   public void doTask() {
      logger.trace("In test  doTask");
      logger.trace("doTask test  complete");
   }

   public static void main(String[] args) {
      logger.warn("Running test code...");
      new TestDbAppender().doTask();
      logger.debug("test Code execution complete.");
   }

}

 

get script from here

 

https://github.com/qos-ch/logback/tree/master/logback-classic/src/main/resources/ch/qos/logback/classic/db/script
This resulted in three tables:

 

 

— Logback: the reliable, generic, fast and flexible logging framework.
— Copyright (C) 1999-2010, QOS.ch. All rights reserved.
— See http://logback.qos.ch/license.html for the applicable licensing
— conditions.
— This SQL script creates the required tables by ch.qos.logback.classic.db.DBAppender
— The event_id column type was recently changed from INT to DECIMAL(40)
— without testing.
DROP TABLE logging_event_property
DROP TABLE logging_event_exception
DROP TABLE logging_event
CREATE TABLE logging_event
(
timestmp DECIMAL(20) NOT NULL,
formatted_message VARCHAR(4000) NOT NULL,
logger_name VARCHAR(254) NOT NULL,
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
reference_flag SMALLINT,
arg0 VARCHAR(254),
arg1 VARCHAR(254),
arg2 VARCHAR(254),
arg3 VARCHAR(254),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
caller_line CHAR(4) NOT NULL,
event_id DECIMAL(40) NOT NULL identity,
PRIMARY KEY(event_id)
)
CREATE TABLE logging_event_property
(
event_id DECIMAL(40) NOT NULL,
mapped_key VARCHAR(254) NOT NULL,
mapped_value VARCHAR(1024),
PRIMARY KEY(event_id, mapped_key),
FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
)
CREATE TABLE logging_event_exception
(
event_id DECIMAL(40) NOT NULL,
i SMALLINT NOT NULL,
trace_line VARCHAR(254) NOT NULL,
PRIMARY KEY(event_id, i),
FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
)

 

 

While this was the console appender, The db appender wrote entries to the table:

Please check 3 tables

Myself

I’m a SharePoint Solutions /SSIS /Biztalk/SQL/ASP.Net Developer currently working for Interpublic Group . I currently specialize in all the integration aspects of Biztalk,
implementing EAI solutions, In SharePoint dvwp, creating webparts, and creating things with jQuery. For 10+ years, I have developed software solutions that
add business value and create cost saving opportunities. I am very
experienced in BizTalk Server 2006/2009/2010/2013 and am consistently recognized by
others for exceeding expectations in the delivery of quality solutions.
Education

MS Software Engineering: Texas University

Technical Certifications

MCTS Biztalk 2006/ 2010

Jin Thakur

 

How to use distinguished fields and promoted properties in a BizTalk Server project

Admin:
How to use distinguished fields and promoted properties in a BizTalk Server project?

When you use distinguished fields and promoted properties, consider the following points:

Use distinguished fields when you want to make decisions or to manipulate data in an orchestration. The pipeline disassembler will insert a Written property into the message context for items that are marked as a distinguished field.
Use promoted properties as criteria for message routing. However, notice that promoted properties are also available in an orchestration. The pipeline disassembler will insert a Promoted property into the message context for items that are marked as a promoted property.
Promoted properties are limited to 256 characters for performance reasons. For example, promoted properties are limited to 256 characters to improve performance in comparison operations and in storage operations.
Written properties do not have a size limit. However, large values that are written into the message context must still be processed by BizTalk Server. Therefore, performance may be affected.
A promoted property may not be available as a promoted property after you write a value into the message context. This situation can occur if the value that you write into the message context has the same name and namespace that was used to promote the property.
Properties that have a null value are not permitted in the message context. Therefore, if a null value is written into the message context, this value will be deleted.

New WCF schema and other schema with namespace does not work in same way as it was in Biztalk 2009

New WCF schema and other schema with namespace does not work in same way as it was in Biztalk 2009

//CALLINGCARD or ./CALLINGCARD does not work in XSLT foreach loop

We have to add Local name for element and attributes

example "*[local-name()='CALLINGCARD' and namespace-uri()='http://Microsoft.LobServices.Sap/2007/03/Rfc/']"

New WCF schema and other schema with namespace does not work in same way as it was in Biztalk 2009
8-)8-)8-)8-)|-)|-)(bo)(bo)(bo)(bo)(bo)(bo)
Previous code

<xsl:element name="ItemCollection">
<xsl:for-each select="//*[local-name()='Root' and namespace-uri()='http://schemas.microsoft.com/BizTalk/2003/aggschema']/*[local-name()='InputMessagePart_0' and namespace-uri()='']/*[local-name()='TESTRFCMESSAGE' and namespace-uri()='http://Microsoft.LobServices.Sap/2007/03/Rfc/']">

<xsl:element name="Item">

<xsl:element name="Value">
<xsl:attribute name="CssClass">table_item_info</xsl:attribute>
<xsl:attribute name="Text" >
<xsl:value-of select="//CALLINGCARD"/>
</xsl:attribute>
</xsl:element>

<xsl:element name="Value">
<xsl:attribute name="CssClass">table_item_info</xsl:attribute>
<xsl:attribute name="Text" >
<xsl:value-of select="//RESULT"/>
</xsl:attribute>
</xsl:element>

</xsl:element>
</xsl:for-each>