• No results found

Contents. Apache Log4j. What is logging. Disadvantages 15/01/2013. What are the advantages of logging? Enterprise Systems Log4j and Maven

N/A
N/A
Protected

Academic year: 2021

Share "Contents. Apache Log4j. What is logging. Disadvantages 15/01/2013. What are the advantages of logging? Enterprise Systems Log4j and Maven"

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

1 Enterprise Systems

Log4j and Maven

Behzad Bordbar Lecture 4 2

Contents

• Log4j and slf4j What is logging Advantages Architecture • Maven What is maven Terminology Demo 3

Apache Log4j

• This will be a brief lecture: you can learn more from various tutorials and available bookd:

• http://jakarta.apache.org/log4j

• http://supportweb.cs.bham.ac.uk/documentatio n/tutorials/docsystem/build/tutorials/log4j/log4j .html

• Samudra Gupta: Pro Apache log4j

4

What is logging

• Gupta’s book:

• Logging is a systematicand controlledway of representing the stateof an application in a

human-readable fashion • State: value of some/all variables

• Most people use system.out.println or debuggers.

• But logs are different from both of the above.

5

What are the advantages of logging?

• Problem diagnosis

• Quick debugging

• Easy maintanance

• History

• Cost and time saving

I’d like to add the following from my research on

process mining.what is PM?

Load balancing, identifying bottlenecks, common scenarios.

6

Disadvantages

• Extra runtime overhead

• Programming overhead- more code can mean more errors

• Bad logs confuse people

• Imposes extra requirements (means allocation of resources= money)

(2)

7

logging is much better than println

1. You can turn a log off to focus on a special aspect of the system

2. Println can not separate log-messages of different degree of importance

3. println just writes to console

8

Three main objects in log4j

• Logger: captures logging information.

• Appender: publishes logging information to various destinations (console, file, socket, .. )

–For example, a ConsoleAppenderobject for printing logging information to a console.

Layout: The Layout object is used to format logging information in different styles (human-readable part!)

9

Interaction of the three objects:

10

How does it work in practice?

Three ways to configure log4j

• Properties file- log4j.properties • XML style of representation

• Programmatic style

We choose the first one- for the other two methods of configuration see

http://jakarta.apache.org/log4j

11

How does it work in practice?

• 1. Name a Logger object for the class

private static final Log LOG = LogFactory.getLog(Main.class); • 2. Insert desired txt with level logging via

Level-Based Logging Methods

• LOG.fatal(“House is on fire"); • 3. Specify Level of logging for the directory and

type of Appenderin log4j.properties

12

How does it work in practice?

• Example:

• log4j.logger.org.hibernate.SQL=deb ug,stdout

• Logging related to org.hibernate.SQLwill be carried out at the level of “debug” and will be appended to stdout.

• How does it work?

• What happens to subpackages?

• What if org.hibernatehas different level? We will answer these next.

(3)

13

Logger object

• The main object that you deal with is a Logger object- everything else behind the scene.

• A convenient way is to get it is:

private static final Log LOG = LogFactory.getLog(ClassNAME.class) • Notice: we can assign the logger in properties file

and then retrieve it using

• public static Logger getRootLogger(); • public static Logger

getLogger(String name); 14

Level-Based Logging Methods

• public void debug(Object message);

• This method prints messages with the level Level.DEBUG.

• There are similar methods for other 7 Levels:

• ALL<DEBUG<INFO<WARN<ERROR<FATAL<OFF • ALL: means all information will be logged

• OFF: means nothing will be logged

• Each Level prints messages about higher level

• Explain!

15

Level-Based Logging Methods

• The configuration can be altered from the

log4j.properties; So we can have different level of logging at different time. For example looking at only FATAL messages.

• There are also Filterobjects to analyze logging information. Filterare beyond the level of this course, see log4j manual

16

Logger Hierarchy

• There is a hierarchy in • log4j.logger.org.hibernate.tool.h bm2ddl=debug,stdout • as follows: • org.hibernate. • org.hibernate.tool • org.hibernate.tool.hbm2ddl • What if Level for some layers are not specified?

17

Level Inheritance

The inherited level for a given logger C, is equal to the first non-null level in the logger hierarchy, starting at C and proceeding upwards in the hierarchy towards the root logger.

• Draw a picture and explain

18

Conditions of Successful Logging

• Using the logging methods does not guarantee

publishing the info

Logging messages with level less than logger level will be ignored: Any logging information

will be approved by a logger if and only if the level p associated with the logging messageis greater than or equal to the level q assigned to the logger

• The Appenderobjects can use Filterand further reject- but this does not apply to us

(4)

19

Biolerplate code for writing to file

• log4j.appender.file= • org.apache.log4j.FileAppender • log4j.appender.stdout.Target=hibernate.log • log4j.appender.stdout.layout=org.apach e.log4j.PatternLayout • log4j.appender.stdout.layout.Conversio nPattern=%d{ABSOLUTE} %5p %c{1}:%L -%m%n

Then we can write: • log4j.rootLogger=info,file

20

Maven

• What is maven?

• How does it work?

• A simple pom.xml

• Command line demo

• Creating eclipse projects (eclipse plugin for maven)

• Using maven within eclipse

21

What is maven?

maven.apache.org says:

Maven is a project management and comprehension tool and that helps with managing:

• Builds (similar to Ant, but not identical) • Documentation

• Reporting • Dependencies

• Software Configuration Management (SCMs) git • Releases

• Distribution

We only use dependencies and build.

22

Architecture of maven (simplified)

• Application

• Local Repository (for example: /.m2/repository/)

• Maven Repository

Application pulls jar files from Local Repository and (central) Maven Repository

Copies from Maven Repository to local

You can also install to Local Repository and Maven Repository

Picture

23

Installatin

• s1) Download file extract (maven.apache.org)

• 2) set variables

• export M2_HOME= path to where you installed maven

• export PATH: Append path to bin folder of where u installed maven to path

Use

1. Command line

2. Throug IDES (Eclipse, Netbeans,….)

24

Maven terminology

• Running archetype-generate produces the following

• Archetype: is a model on how you want your project to be structured.

• Version: is different versions of the archetype

• groupId: similar to packagename

• artifactId: similar to class name (name of the jar or war)

• package: what do u want it to be packaged to. For example jar

(5)

25

Maven Life Cycle (not all)

• compile: usual compile file

• test: all test cases are run

• Package: produces jar or war or...

• install: install the package to local repository (NOT installing into tomcat or…).

• deploy: You deploy to Maven Remote Repository. [NOT deploy into application sever; confusing ].

• clean: to get rid of whatever was created since generation(target …)

26

L

References

Related documents

Reputa?on  and  Indirect  Reciprocity   • Reciprocal  altruism  can  be  stable  even  when   interac?ons  between  par?cular  pairs  of   individuals  unlikely  to

AC 800F Controller, redundant Profibus, redundant S800 I/O, redundant S700 I/O S900 I/O, redundant S700 Profibus remote I/O Foundation Fieldbus Profibus AC 800F Controller Drives

If one is not configured the default root LoggerConfig, which has a level of ERROR and has a Console appender attached, will be used.. The main differences between the root logger

According to Rule 3 of The Central Excise Valuation According to Rule 3 of The Central Excise Valuation (Determination of price of Excisable Goods) Rules, (Determination of price

Since we know now who this third power is, found in Revelation 16:13, that shall go forth with the Dragon (Illuminati) and the Beast (Papacy) unto the whole world to gather

If you really begin to change - if you really surrender your life to God - if you really begin to do as Christ did, to live as He lived - you will be persecuted. Notice II Timothy

•  One mole of molecules or formula units contains Avogadro s number times the number of atoms or ions of each element in the compound... Stoichiometry

• If the merchant continues to support a magnetic stripe only POS solution, they will begin bearing the cost of counterfeit chargebacks if the magnetic stripe on a chip card