Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access logging to Console - PAYARA-729 #787

Merged
merged 2 commits into from May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,8 +37,8 @@
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright
holder.

-->
<!-- Portions Copyright [2014-2016] [C2B2 Consulting Limited] -->

<!-- configuration/accessLog.jsf -->

Expand Down Expand Up @@ -98,6 +98,10 @@
<sun:property id="acLog" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18n_web.vs.accessLogging}">
<sun:checkbox id="accessLoggingEnabled" label="$resource{i18n.common.Enabled}" selected="#{pageSession.valueMap['accessLoggingEnabled']}" selectedValue="true"/>
</sun:property>
<sun:property id="logToConsoleProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18n_web.access.LogToConsole}" helpText="$resource{i18n_web.access.LogToConsoleHelp}">
<sun:checkbox label="$resource{i18n.common.Enabled}" selected="#{pageSession.valueMap2['logToConsoleEnabled']}" selectedValue="true" >
</sun:checkbox>
</sun:property>

<sun:property id="rotationProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18n_web.access.Rotation}" helpText="$resource{i18n_web.access.RotationHelp}">
<sun:checkbox label="$resource{i18n.common.Enabled}" selected="#{pageSession.valueMap2['rotationEnabled']}" selectedValue="true" >
Expand Down
Expand Up @@ -95,6 +95,8 @@ access.accessLogWriteIntervalHelp=Interval between writing (updating) the access
access.SsoEnbaled=SSO:
access.SsoEnabledHelp=Enable single sign-on by default for all web applications
access.SectionTitle=Access Logging
access.LogToConsole=Console Logging:
access.LogToConsoleHelp=Enable access logging to the console
access.Rotation=Rotation:
access.RotationHelp=Enable access log rotation
access.RotationPolicy=Rotation Policy:
Expand Down
Expand Up @@ -37,27 +37,21 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2014-2016] [C2B2 Consulting Limited]

package com.sun.enterprise.web;

import com.sun.enterprise.config.serverbeans.*;
import com.sun.enterprise.config.serverbeans.VirtualServer;
import com.sun.enterprise.util.io.FileUtils;
import com.sun.enterprise.web.accesslog.AccessLogFormatter;
import com.sun.enterprise.web.accesslog.CombinedAccessLogFormatterImpl;
import com.sun.enterprise.web.accesslog.CommonAccessLogFormatterImpl;
import com.sun.enterprise.web.accesslog.DefaultAccessLogFormatterImpl;
import com.sun.enterprise.web.pluggable.WebContainerFeatureFactory;
import com.sun.enterprise.util.io.FileUtils;
import org.apache.catalina.*;
import org.apache.catalina.valves.ValveBase;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.logging.annotation.LogMessageInfo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.String;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
Expand All @@ -68,6 +62,12 @@
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.catalina.*;
import org.apache.catalina.valves.ValveBase;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.LogManager;
import org.glassfish.logging.annotation.LogMessageInfo;

/**
* <p>Implementation of the <b>Valve</b> interface that generates a web server
Expand All @@ -90,6 +90,7 @@ public final class PEAccessLogValve
private static final Logger _logger = com.sun.enterprise.web.WebContainer.logger;

private static final ResourceBundle _rb = _logger.getResourceBundle();
private final LogManager logManager = org.glassfish.internal.api.Globals.get(LogManager.class);

@LogMessageInfo(
message = "Unable to write access log file {0}",
Expand Down Expand Up @@ -301,6 +302,11 @@ public final class PEAccessLogValve
*/
private boolean flushRealTime = true;

/**
* access log to console
*/
private boolean accessLogToConsole = false;


/**
* Are we supposed to add datestamp to first access log file we create,
Expand Down Expand Up @@ -364,6 +370,9 @@ public void setWriterInterval(int t) {
if ( t > 0 ){
flushRealTime = false;
}
else {
flushRealTime = true;
}
writeInterval = t;
}

Expand All @@ -388,7 +397,7 @@ public void setRotationInterval(int t) {
* Set the direct <code>ByteBuffer</code> size
*/
public void setBufferSize(int size){
if ( size > 0 ){
if ( size > 0 && writeInterval != 0){
flushRealTime = false;
}
if (size < MIN_BUFFER_SIZE) {
Expand Down Expand Up @@ -707,8 +716,13 @@ public void log() throws IOException {
synchronized(lock){
try{
charBuffer.flip();
String bufString = charBuffer.toString();
if (accessLogToConsole && !bufString.isEmpty()) {
logManager.getOutStream().print(bufString.replaceAll("(?m)^", "AccessLog: "));
}
ByteBuffer byteBuffer =
ByteBuffer.wrap(charBuffer.toString().getBytes(Charset.defaultCharset()));
ByteBuffer.wrap(bufString.getBytes(Charset.defaultCharset()));

while (byteBuffer.hasRemaining()){
fileChannel.write(byteBuffer);
}
Expand All @@ -720,7 +734,7 @@ public void log() throws IOException {
}

}



/*
Expand Down Expand Up @@ -944,6 +958,9 @@ void updateAccessLogAttributes(HttpService httpService,
} else if (maxHistoryFiles > 0) {
historyFiles = new LinkedList<File>();
}

// log to console
accessLogToConsole = accessLogConfig.getLogToConsoleEnabled();
}


Expand Down
Expand Up @@ -38,7 +38,7 @@
* holder.
*/

// Portions Copyright [2014-2015] [C2B2 Consulting Limited]
// Portions Copyright [2014-2016] [C2B2 Consulting Limited]

package com.sun.enterprise.web;

Expand All @@ -65,18 +65,35 @@
import com.sun.enterprise.web.pluggable.WebContainerFeatureFactory;
import com.sun.enterprise.web.session.SessionCookieConfig;
import com.sun.web.security.RealmAdapter;

import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.catalina.*;
import org.apache.catalina.authenticator.AuthenticatorBase;
import org.apache.catalina.authenticator.SingleSignOn;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.connector.Response;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.ErrorPage;
import org.apache.catalina.valves.RemoteAddrValve;
import org.apache.catalina.valves.RemoteHostValve;

import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.api.deployment.DeployCommandParameters;
Expand All @@ -87,71 +104,40 @@
import org.glassfish.deployment.common.ApplicationConfigInfo;
import org.glassfish.deployment.common.DeploymentContextImpl;
import org.glassfish.deployment.common.DeploymentUtils;
import org.glassfish.embeddable.CommandRunner;
import org.glassfish.embeddable.GlassFishException;
import org.glassfish.embeddable.web.Context;
import org.glassfish.embeddable.web.ConfigException;
import org.glassfish.embeddable.web.Context;
import org.glassfish.embeddable.web.WebListener;
import org.glassfish.embeddable.web.config.VirtualServerConfig;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.ConnectionProbe;
import org.glassfish.grizzly.config.GenericGrizzlyListener;
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.http.ContentEncoding;
import org.glassfish.grizzly.http.HttpContent;
import org.glassfish.grizzly.filterchain.FilterChainContext;
import org.glassfish.grizzly.http.HttpCodecFilter;
import org.glassfish.grizzly.http.HttpProbe;
import org.glassfish.grizzly.http.HttpHeader;
import org.glassfish.grizzly.http.HttpPacket;
import org.glassfish.grizzly.http.HttpProbe;
import org.glassfish.grizzly.http.HttpRequestPacket;
import org.glassfish.grizzly.http.HttpResponsePacket;
import org.glassfish.grizzly.http.TransferEncoding;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.glassfish.grizzly.filterchain.FilterChainContext;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.ServiceLocatorFactory;
import org.glassfish.logging.annotation.LogMessageInfo;
import org.glassfish.web.admin.monitor.RequestProbeProvider;
import org.glassfish.web.deployment.archivist.WebArchivist;
import org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl;

import org.glassfish.internal.api.ClassLoaderHierarchy;
import org.glassfish.internal.api.ServerContext;
import org.glassfish.internal.api.Globals;
import org.glassfish.internal.api.ServerContext;
import org.glassfish.internal.data.ApplicationInfo;
import org.glassfish.internal.data.ApplicationRegistry;
import org.glassfish.internal.deployment.Deployment;
import org.glassfish.internal.deployment.ExtendedDeploymentContext;
import org.glassfish.logging.annotation.LogMessageInfo;
import org.glassfish.web.admin.monitor.RequestProbeProvider;
import org.glassfish.web.deployment.archivist.WebArchivist;
import org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl;
import org.glassfish.web.loader.WebappClassLoader;
import org.glassfish.web.valve.GlassFishValve;

import org.glassfish.hk2.api.ServiceLocator;
import org.jvnet.hk2.config.Transaction;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.types.Property;

import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.LogRecord;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.*;


Expand Down
Expand Up @@ -37,18 +37,18 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2014-2016] [C2B2 Consulting Limited]

package com.sun.enterprise.config.serverbeans;

import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.Configured;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.types.PropertyBag;
import java.beans.PropertyVetoException;

import javax.validation.constraints.Min;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.Configured;
import org.jvnet.hk2.config.types.PropertyBag;

/**
* Access log configuration
Expand Down Expand Up @@ -197,5 +197,18 @@ public interface AccessLog extends ConfigBeanProxy, PropertyBag {
*/
void setMaxHistoryFiles(String value) throws PropertyVetoException;

/**
* Specifies whether to display access logs on the console
*
* @return true if logging to console
*/
@Attribute (defaultValue="false", dataType=Boolean.class)
boolean getLogToConsoleEnabled();
/**
* specifies whether to display access logs to console
*
* @param tf true/false
*/
void setLogToConsoleEnabled(boolean tf);
}

Expand Up @@ -37,11 +37,13 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2014-2016] [C2B2 Consulting Limited]

package org.glassfish.internal.api;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
import java.util.logging.Handler;
import org.jvnet.hk2.annotations.Contract;
Expand All @@ -59,4 +61,7 @@ public interface LogManager {
* @param handler handler to be iadded.
*/
void addHandler(Handler handler);

PrintStream getErrStream();
PrintStream getOutStream();
}