User: ejort
Date: 02/02/08 13:35:39
Added: src/main/org/jboss/mx/logging/file FileLogger.java
FileLoggerFactory.java package.html
Log:
Initial version of logging - might be over-engineered?
Revision Changes Path
1.1 jmx/src/main/org/jboss/mx/logging/file/FileLogger.java
Index: FileLogger.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.logging.file;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.security.AccessController;
import org.jboss.mx.logging.Logger;
import org.jboss.mx.logging.LoggerAdapterSupport;
import org.jboss.mx.logging.LoggerPermission;
/**
* A file logger, the name is the fully qualifed file name.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public final class FileLogger
extends LoggerAdapterSupport
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
/**
* The logging level
*/
private int level = Logger.ALL;
/**
* The file name
*/
private String fileName;
/**
* The print stream for the file
*/
private PrintStream output;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Construct a new FileLogger from the given file name
*
* @param name the file name
*/
public FileLogger(String name)
throws FileNotFoundException
{
this(name, true);
}
/**
* Construct a new FileLogger from the given file name
*
* @param name the file name
* @param append pass true to append to an existing file, false to
* create a new file
*/
public FileLogger(String name, boolean append)
throws FileNotFoundException
{
fileName = name;
output = new PrintStream(new FileOutputStream(name, append), true);
}
// LoggerAdapter Implementation ----------------------------------
public final String getName()
{
return fileName;
}
public final int getLevel()
{
return level;
}
public final void setLevel(int level)
throws SecurityException
{
//TODO AccessController.checkPermission(new LoggerPermission("control"));
this.level = level;
}
public final void log(int level, String message)
{
if (isEnabled(level) == false)
return;
doLog(level, message, null);
}
public final void log(int level, String message, Throwable throwable)
{
if (isEnabled(level) == false)
return;
doLog(level, message, throwable);
}
public final boolean isEnabled(int level)
{
return level <= this.level;
}
/**
* This is a logger implementation.
*
* @return this logger adapter.
*/
public Object getUnderlyingLogger()
{
return this;
}
// Y Overrides ---------------------------------------------------
// Protected -----------------------------------------------------
// Package Private -----------------------------------------------
// Private -------------------------------------------------------
/**
* Perform the actual logging to system error.
*
* @param level the logging level
* @param message the message
* @param throwable an error
*/
private final void doLog(int level, String message, Throwable throwable)
{
synchronized(output)
{
if (level == Logger.FATAL)
output.print("FATAL ");
if (level == Logger.ERROR)
output.print("ERROR ");
if (level == Logger.WARN)
output.print("WARN ");
if (level == Logger.INFO)
output.print("INFO ");
if (level == Logger.DEBUG)
output.print("DEBUG ");
if (level == Logger.TRACE)
output.print("TRACE ");
output.println(message);
if (throwable != null)
throwable.printStackTrace(output);
}
}
// Inner classes -------------------------------------------------
}
1.1 jmx/src/main/org/jboss/mx/logging/file/FileLoggerFactory.java
Index: FileLoggerFactory.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.logging.file;
import java.io.FileNotFoundException;
import org.jboss.mx.logging.LoggerAdapter;
import org.jboss.mx.logging.LoggerAdapterFactorySupport;
/**
* A file logger factory. The logger name is used as the file name.
*
* @see FileLogger
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public final class FileLoggerFactory
extends LoggerAdapterFactorySupport
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// LoggerAdapterFactory Implementation --------------------------
public final LoggerAdapter getLoggerAdapter(String name)
{
try
{
return new FileLogger(name);
}
catch (FileNotFoundException nfe)
{
throw new RuntimeException(nfe.toString());
}
}
public final Class getLoggerAdapterClass()
{
return FileLogger.class;
}
// Y Overrides ---------------------------------------------------
// Protected -----------------------------------------------------
// Package Private -----------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1 jmx/src/main/org/jboss/mx/logging/file/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!--
JBoss, the OpenSource J2EE webOS
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-->
<!-- $Id: package.html,v 1.1 2002/02/08 21:35:39 ejort Exp $ -->
</head>
<body bgcolor="white">
<p><em>The JBossMX file logger</em>.
<h2>Package Specification</h2>
<ul>
<li> A simple file logger that uses the logger name as the file name.
</ul>
<h2>Related Documentation</h2>
<ul>
</ul>
<h2>Package Status</h2>
<ul>
<li><font color="red"><b>ALPHA</b></font>
</ul>
<!-- Put @see and @since tags down here. -->
</body>
</html>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development