23-Jun-15 Logging. What is logging? “Logging” is producing messages that tell you what your program is doing It’s not much different than using System.out.println(...)

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Logging in Java applications Sean C. Sullivan July 23, 2002 Portland Java Users Group.
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
CHAPTER 12 GENERICS Introduction to java 1. Assignment 5 Solution See Eclipse.
CMSC 202 Exceptions 2 nd Lecture. Aug 7, Methods may fail for multiple reasons public class BankAccount { private int balance = 0, minDeposit =
MIT-AITI Lecture 14: Exceptions Handling Errors with Exceptions Kenya 2005.
Debugging & Logging. Java Logging Java has built-in support for logging Logs contain messages that provide information to – Software developers (e.g.,
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
Lecture 28 More on Exceptions COMP1681 / SE15 Introduction to Programming.
11-Jun-15 Exceptions. 2 Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a.
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
26-Jun-15 Logging. What is logging? “Logging” is producing messages that tell you what your program is doing It’s not much different than using System.out.println(...)
28-Jun-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
13-Jul-15 Logging. What is logging? “Logging” is producing messages that tell you what your program is doing It’s not much different than using System.out.println(...)
CSE 131 Computer Science 1 Module 1: (basics of Java)
dcDB Stored Procedures: An Overview
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Exception Handling in Java Exception Handling Introduction: After completing this chapter, you will be able to comprehend the nature and kinds.
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
COSC 1P03 Data Structures and Abstraction 4.1 Abstract Data Types The advantage of a bad memory is that one enjoys several times the same good things for.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
COEN 252: Computer Forensics Network Analysis and Intrusion Detection with Snort.
1 Software Construction and Evolution - CSSE 375 Exception Handling – Logging & Special Situations Steve Chenoweth Office: Moench Room F220 Phone: (812)
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
CIT 590 Intro to Programming First lecture on Java.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Software Documentation Section 5.5 ALBING’s Section JIA’s Appendix B JIA’s.
Logging1. 2 Introduction Ships must keep a written log telling speed, direction, destination, etc. –A kind of diary of the ship. Large programs should.
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel
Odds and Ends. CS 21a 09/18/05 L14: Odds & Ends Slide 2 Copyright © 2005, by the authors of these slides, and Ateneo de Manila University. All rights.
Mobile Programming Lecture 3 Debugging. Lecture 2 Review What widget would you use to allow the user to enter o a yes/no value o a range of values from.
Javadoc. Purpose of javadoc javadoc is a program that reads your Java program and produces great-looking documentation in HTML format Without any help,
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Exceptions Handling Exceptions with try and catch The finally-block The throws.
CIT 590 Intro to Programming Lecture 13. Some Eclipse shortcuts CTRL + SHIFT + F – format file (proper indentation etc). Please do this before you submit.
Creating a GUI Class An example of class design using inheritance and interfaces.
SE1011 Week 5, Class 1 Today More Java API tools Packages Object Oriented Programming Muddiest Point Tomorrow: Lab 5 – In-lab demo requirements now up.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
OOP Basics Classes & Methods (c) IDMS/SQL News
Java Input and Output. Java Input  Input is any information needed by your program to complete its execution  So far we have been using InputBox for.
Introduction to Exceptions in Java CS201, SW Development Methods.
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CVS, Logging, Development
Summary prepared by Kirk Scott
Class Structure 15-Jun-18.
Some Eclipse shortcuts
Exceptions 10-Nov-18.
Exceptions 10-Nov-18.
Handling Exceptions.
Class Structure 16-Nov-18.
Class Structure 7-Dec-18.
Debugging & Logging.
Class Structure 2-Jan-19.
Exceptions 19-Feb-19.
Class Structure 25-Feb-19.
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
CSC 143 Java Errors and Exceptions.
slides created by Ethan Apter
Exceptions 10-May-19.
Visibilities and Static-ness
Exceptions 5-Jul-19.
CMSC 202 Exceptions.
CS 240 – Advanced Programming Concepts
Presentation transcript:

23-Jun-15 Logging

What is logging? “Logging” is producing messages that tell you what your program is doing It’s not much different than using System.out.println(...) Log messages can go to the console, to a file, or one of several other places (e.g. sent over the Internet) You can use logging to help you debug a program You can use logging to produce a file when the user runs your program If there are problems, you can ask the user to send you the log file

Basic use import java.util.logging.*; private static Logger myLogger = Logger.getLogger("myPackage"); myLogger.log(Level.SEVERE, "Bad news!"); Aug 15, :51:09 AM myPackage.Sync main SEVERE: Bad news!

Logging levels and methods Level.SEVERE Level.WARNING Level.INFO Level.CONFIG Level.FINE Level.FINER Level.FINEST These levels are ordered, so that you can set the level of severity that results in log messages However, the levels have no inherent meaning--they are what you make of them myLogger.severe(String msg ); myLogger.warning(String msg ); myLogger.info(String msg ); myLogger.config(String msg ); myLogger.fine(String msg ); myLogger.finer(String msg ); myLogger.finest(String msg );

Controlling logging levels public void Logger.setLevel(Level newLevel ) Sets the logger to log all messages at newLevel or above Logger calls at lower levels don’t do anything Example: logger.setLevel(Level.WARNING); Additional settings: logger.setLevel(Level.ALL); logger.setLevel(Level.OFF); public Level getLevel() Note that this returns a Level, not an int Level has intValue() and toString() methods

Additional Logger methods void entering(String sourceClass, String sourceMethod ) void entering(String sourceClass, String sourceMethod, Object param1 ) void entering(String sourceClass, String sourceMethod, Object[] params ) void exiting(String sourceClass, String sourceMethod ) void exiting(String sourceClass, String sourceMethod, Object result ) These log messages at level FINER

Logging flow of control You send your message to a Logger The Logger checks a Filter to see whether to ignore the message The Logger sends the message to a Handler to put the message somewhere The Handler checks another Filter to see whether to ignore this kind of message sent to this destination The Handler calls a Formatter to decide what kind of a text string to produce The Handler sends the formatted message somewhere Logger Handler Filter Formatter applicationdestination

Filters Filter is an interface; it defines the single method boolean isLoggable(LogRecord record ) A LogRecord is another class in java.util.logging ; it provides numerous methods for examining the proposed logging message We won’t go into the details of LogRecord in this lecture (see the API if you need to use this)

Logging formatting and destinations The JDK defines five Handlers: StreamHandler : sends messages to an OutputStream ConsoleHandler : sends messages to System.err (default) FileHandler : sends messages to a file SocketHandler : sends messages to a TCP port MemoryHandler : buffers messages in memory It also defines two ways to format messages: SimpleFormatter (default) XMLFormatter And, of course, you can define your own Handler s and Formatter s As you can tell from the “Basic Use” slide earlier, you can ignore all of this and just use the defaults

Using a FileHandler try { logger.addHandler(new FileHandler("myLogFile")); } catch (SecurityException e) { e.printStackTrace(); } The default Formatter for a FileHandler is XMLFormatter

FileHandler results T13:21: myPackage SEVERE myClass main 10 Bad news!

The rest of the story As usual, I’ve only given you a few features beyond the most basic usage If you want to know about Filter s, other destinations than the console or a file, etc., it’s all in the Java API You should also know that there is an alternative open source logging package, log4j log4j has been around longer than Sun’s logging package Many people feel that log4j is better I didn’t cover it because it isn’t installed in the labs here

The End