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(...)

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.
„Exceptions”. Exceptions Handling errors with exceptions Golden rule of programming: Errors occur in software programs. What really matters is what happens.
CHAPTER 12 GENERICS Introduction to java 1. Assignment 5 Solution See Eclipse.
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 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.
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(...)
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(...)
15-Jul-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.
CSE 131 Computer Science 1 Module 1: (basics of Java)
CIS 068 JAVA I/O: Streams and Files. CIS 068 I/O Usual Purpose: storing data to ‘nonvolatile‘ devices, e.g. harddisk Classes provided by package java.io.
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.
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)
Handling Exceptions in java. Exception handling blocks try { body-code } catch (exception-classname variable-name) { handler-code }
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Java I/O Java I/O is based on input streams and output streams. All input and output are defined in the Java IO package. 1.
CIT 590 Intro to Programming First lecture on Java.
ACS Logging System APIs: C++ Bogdan Jeram European Southern Observatory July 2004NRAO.
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:
Logging1. 2 Introduction Ships must keep a written log telling speed, direction, destination, etc. –A kind of diary of the ship. Large programs should.
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.
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.
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.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
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.
Exceptions Part II. What you need to know Last time –What happens when an exception is thrown –What are your choices for handling exceptions –The different.
CVS, Logging, Development
Class Structure 15-Jun-18.
Some Eclipse shortcuts
Exceptions 10-Nov-18.
Exceptions 10-Nov-18.
Handling Exceptions.
Class Structure 16-Nov-18.
How to Run a Java Program
IO Overview CSCE 121 J. Michael Moore
Class Structure 7-Dec-18.
Debugging & Logging.
Class Structure 2-Jan-19.
How to Run a Java Program
Exceptions 19-Feb-19.
Class Structure 25-Feb-19.
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
CSC 143 Java Errors and Exceptions.
Exceptions 10-May-19.
Visibilities and Static-ness
Exceptions 5-Jul-19.
CMSC 202 Exceptions.
CS 240 – Advanced Programming Concepts
Presentation transcript:

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(...) 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 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

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