Showing posts with label Gradle. Show all posts
Showing posts with label Gradle. Show all posts

Friday, 31 March 2017

Step wise how to set up GIT in eclipse

Step wise how to set up GIT in eclipse


Read my previous post about step wise how to create and merge new branch in GIT.

Step 1: 

Step wise how to set up GIT in eclipse


Step wise how to set up GIT in eclipse

Step 3: Select first option.

Step wise how to set up GIT in eclipse

Step wise how to set up GIT in eclipse

Step wise how to set up GIT in eclipse

Step 4: Click yes and installation complete.

Step wise how to set up GIT in eclipse

Step 5: Open customised perspective.

Step wise how to set up GIT in eclipse

Step 6: Select Git. It will add options in toolbar.

Step wise how to set up GIT in eclipse
Step 7: Go to preference.

Step wise how to set up GIT in eclipse

Step 8: Click on git and give path of local  repository created in earlier post.

Step wise how to set up GIT in eclipse

Step 9: Give email and name in configuration.
               user.name and user.email

Step wise how to set up GIT in eclipse

Step 10: Right click in project Explorer and go to import.

Step wise how to set up GIT in eclipse

Step 11: Select projects from git.

Step wise how to set up GIT in eclipse

Step 12: Select Existing local repository.

Step wise how to set up GIT in eclipse

Step 13: Click on Add.

Step wise how to set up GIT in eclipse

Step 14: Check the box. And click finish.

Step wise how to set up GIT in eclipse

Step 15: Select Git Repository name and next.

Step wise how to set up GIT in eclipse

Step 16: Select Import a general project and select on project name & click next.

Step wise how to set up GIT in eclipse

Step wise how to set up GIT in eclipse


Step 17: We can see project structure having src , WebContent and build.gradle if project is gradle.

Step wise how to set up GIT in eclipse

Step 18: Right click on project and configure then Add Gradle Nature.

Step wise how to set up GIT in eclipse


Related post:

Step wise how to create and merge new branch in GIT


Friday, 17 March 2017

Stepwise how to implement spring logging with log4j

Step wise how to implement spring logging with log4j

Logging is very important for any application its give us insider information about application about its background and what happens in the application at debug and run time.

Logging is broken into three major pieces: the Logger, Formatter and the Handler (Appender). The Logger is responsible for capturing the message to be logged along with certain metadata and passing it to the logging framework. After receiving the message, the framework calls the Formatter with the message. The Formatter formats it for output. The framework then hands the formatted message to the appropriate Appender for disposition. This might include a console display, writing to disk, appending to a database, or email.


I will discuss on this post, how LOG4J property file to write output on log file and show on console as well.

Step 1: Download log4j.x.x.x.jar and copy it in lib folder of your project. If you are using Maven than add log4j dependency to your pom.xml like this.

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

<dependency>
    <groupId>log4j</groupId>
    <artifactId>apache-log4j-extras</artifactId>
    <version>1.2.17</version>
</dependency>

If you are using Gradle than add log4j dependency to your build.gradle like this.

//LOG4J
    compile 'log4j:log4j:1.2.17'
    compile 'log4j:apache-log4j-extras:1.2.17'

Step 2: Add one of the configuration file either property file or xml file to your project and make sure the file is included in classpath.

Stepwise how to implement spring logging with log4j

# LOG4J configuration
log4j.rootLogger=INFO, CONSOLE, FILE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.logger.org.hibernate =WARN

log4j.appender.FILE=org.apache.log4j.rolling.RollingFileAppender 
log4j.appender.FILE.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 
log4j.appender.FILE.rollingPolicy.maxIndex=2 
log4j.appender.FILE.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 
#log4j.appender.FILE.triggeringPolicy.MaxFileSize=5000000
log4j.appender.FILE.triggeringPolicy.MaxFileSize=50000
log4j.appender.FILE.rollingPolicy.FileNamePattern=D:/Error-%i.log 
log4j.appender.FILE.rollingPolicy.ActiveFileName=D:/Error.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 
log4j.appender.FILE.layout.ConversionPattern=%d %-5p - %c %x %m%n

Step 3: Add required logging code to your project classes where you want to enable logging and store activities.
private static final Logger logger = Logger.getLogger(Home.class); // register class with logger
logger.info("Message info");  // implement required logging method

1.    package com.engineeernitesh.controller;

2.    import org.apache.log4j.BasicConfigurator;
3.    import org.apache.log4j.Logger;
4.    import org.springframework.stereotype.Controller;
5.    import org.springframework.web.bind.annotation.RequestMapping;
6.    import org.springframework.web.servlet.ModelAndView;

7.    @Controller
8.    public class Test {
9.    User user = new User();

10.  private static final Logger logger = Logger.getLogger(Test.class);

11.  @RequestMapping("/hello")
12.  public ModelAndView hello(){
13.       BasicConfigurator.configure();
14.       logger.debug("Debug..");
15.       logger.info("Info.."+user);
16.       logger.error("Error.."+user);
17.       logger.fatal("Fatal"+user);
18.       logger.trace("trace");
19.       return new ModelAndView("hello","message","HelloWorld");
20.      }
21.  }



Related Post:

How to turning off hibernate logging console output

How can I disable application context info in log or console