2014-07-07

Logback colors

Coloring in Logback

Grouping by parentheses as explained above allows coloring of sub-patterns. As of version 1.0.5, PatternLayout recognizes "%black", "%red", "%green","%yellow","%blue", "%magenta","%cyan", "%white", "%gray", "%boldRed","%boldGreen", "%boldYellow", "%boldBlue", "%boldMagenta""%boldCyan", "%boldWhite" and "%highlight" as conversion words. These conversion words are intended to contain a sub-pattern. Any sub-pattern enclosed by a coloring word will be output in the specified color.

Below is a configuration file illustrating coloring. Note the %cyan conversion specifier enclosing "%logger{15}". This will output the logger name abbreviated to 15 characters in cyan. The %highlight conversion specifier prints its sub-pattern in bold-red for events of level ERROR, in red for WARN, in BLUE for INFO, and in the default color for other levels.

Example: Highlighting levels (logback-examples/src/main/java/chapters/layouts/highlighted.xml) View as .groovy


<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- On Windows machines setting withJansi to true enables ANSI
         color code interpretation by the Jansi library. This requires
         org.fusesource.jansi:jansi:1.8 on the class path.  Note that
         Unix-based operating systems such as Linux and Mac OS X
         support ANSI color codes by default. -->
<withjansi>true</withJansi>
<encoder>
<pattern>[%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>



Here is the corresponding output:

[main] WARN c.l.TrivialMain - a warning message 0
[main] DEBUG c.l.TrivialMain - hello world number1
[main] DEBUG c.l.TrivialMain - hello world number2
[main] INFO c.l.TrivialMain - hello world number3
[main] DEBUG c.l.TrivialMain - hello world number4
[main] WARN c.l.TrivialMain - a warning message 5
[main] ERROR c.l.TrivialMain - Finish off with fireworks

It takes very few lines of code to create a coloring conversion word. The section entitled creating a custom conversion specifier discusses the steps necessary for registering a conversion word in your configuration file.

2014-03-09

spring 3.x +hibernate 4

test out div
test in div
pom.xml:

 4.0.0
 pl.kropladev
 spring-hibernate
 0.0.1-SNAPSHOT
 war
 

  
  1.6
  UTF-8
  1.6
  3.0
 
  
  2.2
  1.2
  2.5

  
  3.2.6.RELEASE
  1.5.0.RELEASE

  
  11.2.0.4

  
  4.1.5.Final
  4.2.0.Final

  
  1.0.13
  1.7.5

  
  4.11


 

 
  
   
    maven-compiler-plugin
    ${maven.version}
    
     ${compiler.version}
     ${compiler.version}
    
   

  
 
 
 
  
  
   org.springframework
   spring-context-support
   ${spring-framework.version}
  

  
  
   com.oracle
   ojdbc5
   ${oracle.ojdbc.version}
  

  
   org.springframework
   spring-jdbc
   ${spring-framework.version}
  

  
   org.springframework.data
   spring-data-jpa
   ${spring-jpa.version}
  

  
  
   org.springframework
   spring-orm
   ${spring-framework.version}
  
  
   
    org.hibernate
    hibernate-core
    ${hibernate.version}
   
  
   
    org.hibernate
    hibernate-validator
    ${hibernate-validator.version}
   
  
  

   
    org.slf4j
    slf4j-api
    ${slf4j.version}
    compile
   

   
    ch.qos.logback
    logback-classic
    ${logback.version}
    runtime
   

   
    commons-dbcp
    commons-dbcp
    1.4
   

   
   
    junit
    junit
    ${junit.version}
    test
   

   
    javax.servlet
    servlet-api
    ${servlet.version}
   

 



repository.xml:



  

  
    
    
    
      
        org.hibernate.dialect.Oracle10gDialect
        true
      
    
  

  
  
    
   



2014-03-06

Eclipse jstl errors

The error message: 

Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

 Overview: 

JSTL (JSP Standard Tag Library) is a JSP based standard tag library which offers tags usefull for page creation.
The jstl/core resides in jstl jar package. Till version 1.0 it was placed inside the main directory and definition to it was:
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

 From version 1.1 the correct definition is:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

Solution: 

In the project preferences check the Target servers settings. When those settings are ok, try to remove and add one more time the server.

more details:
http://stackoverflow.com/tags/jstl/info

2014-02-23

Spring mvc framework context loaded twice??

Context

I have developed the simple scheduler (task timer) application using spring framework with mvc.
Application only log "Hello!!" string every 10 seconds.

Code example

spring-servlet.xml:



web.xml:






Surprisingly in logs I've noticed double logs with hello string?? WTF?

Looking into context start logs

2014-02-23T23:18:08|INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring root WebApplicationContext
2014-02-23T23:18:08|INFO: Root WebApplicationContext: initialization started
2014-02-23T23:18:08|INFO: Refreshing Root WebApplicationContext: startup date [Sun Feb 23 23:18:08 CET 2014]; root of context hierarchy
2014-02-23T23:18:09|INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/springmvc-servlet.xml]
2014-02-23T23:18:09|INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2014-02-23T23:18:09|INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@88fb55: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,runScheduler,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.context.annotation.internalScheduledAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
2014-02-23T23:18:09|INFO: Hello!!
2014-02-23T23:18:09|INFO: Root WebApplicationContext: initialization completed in 838 ms
2014-02-23T23:18:09|INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'springmvc'
2014-02-23T23:18:09|INFO: FrameworkServlet 'springmvc': initialization started
2014-02-23T23:18:09|INFO: Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Sun Feb 23 23:18:09 CET 2014]; parent: Root WebApplicationContext
2014-02-23T23:18:09.590+0100|INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/springmvc-servlet.xml]
2014-02-23T23:18:09|INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2014-02-23T23:18:09|INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3d2bac: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,runScheduler,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.context.annotation.internalScheduledAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@88fb55
2014-02-23T23:18:09|INFO: Mapped URL path [/welcome] onto handler 'helloController'
2014-02-23T23:18:09|INFO: Mapped URL path [/welcome.*] onto handler 'helloController'
2014-02-23T23:18:09|INFO: Mapped URL path [/welcome/] onto handler 'helloController'
2014-02-23T23:18:09|INFO: Hello!!
2014-02-23T23:18:09|INFO: FrameworkServlet 'springmvc': initialization completed in 383 ms

 Solution

Context was loaded twice from /WEB-INF/springmvc-servlet.xml config file.  
contextConfigLocation is uncorrectly invoke. It should point on spring application context definition (different than servlet definition - springmvc-servlet.xml).
Changing to other applicationConfig.xml should help fix the problem:


Eclipse glassfish error

When I'm trying to run glassfish (ver. 3.1) from the eclipse servers view, its only show error message:

bootstrap jar not found

Solution:
Check if glassfish server is proper configured on Window->Preferences-Server->Runtime Environment-GlassFish 3.1

Checking which services will be started on linux boot

- list of all services with levels of run
ls /etc/rc*.d

- install configuration editor
sudo apt-get install rcconf sysv-rc-conf