idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
2,600
private boolean passesExpression ( LoggingEvent event ) { if ( event != null ) { if ( expressionRule != null ) { return ( expressionRule . evaluate ( event , null ) ) ; } } return true ; }
Helper method that supports the evaluation of the expression
2,601
private String convertTimestamp ( ) { String result = timestampFormat . replaceAll ( VALID_DATEFORMAT_CHAR_PATTERN + "+" , "\\\\S+" ) ; result = result . replaceAll ( Pattern . quote ( "." ) , "\\\\." ) ; return result ; }
Helper method that will convert timestamp format to a pattern
2,602
private String replaceMetaChars ( String input ) { input = input . replaceAll ( "\\\\" , "\\\\\\" ) ; input = input . replaceAll ( Pattern . quote ( "]" ) , "\\\\]" ) ; input = input . replaceAll ( Pattern . quote ( "[" ) , "\\\\[" ) ; input = input . replaceAll ( Pattern . quote ( "^" ) , "\\\\^" ) ; input = input . replaceAll ( Pattern . quote ( "$" ) , "\\\\$" ) ; input = input . replaceAll ( Pattern . quote ( "." ) , "\\\\." ) ; input = input . replaceAll ( Pattern . quote ( "|" ) , "\\\\|" ) ; input = input . replaceAll ( Pattern . quote ( "?" ) , "\\\\?" ) ; input = input . replaceAll ( Pattern . quote ( "+" ) , "\\\\+" ) ; input = input . replaceAll ( Pattern . quote ( "(" ) , "\\\\(" ) ; input = input . replaceAll ( Pattern . quote ( ")" ) , "\\\\)" ) ; input = input . replaceAll ( Pattern . quote ( "-" ) , "\\\\-" ) ; input = input . replaceAll ( Pattern . quote ( "{" ) , "\\\\{" ) ; input = input . replaceAll ( Pattern . quote ( "}" ) , "\\\\}" ) ; input = input . replaceAll ( Pattern . quote ( "#" ) , "\\\\#" ) ; return input ; }
Some perl5 characters may occur in the log file format . Escape these characters to prevent parsing errors .
2,603
public void shutdown ( ) { getLogger ( ) . info ( getPath ( ) + " shutdown" ) ; active = false ; try { if ( reader != null ) { reader . close ( ) ; reader = null ; } } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } }
Close the reader .
2,604
public void activateOptions ( ) { getLogger ( ) . info ( "activateOptions" ) ; active = true ; Runnable runnable = new Runnable ( ) { public void run ( ) { initialize ( ) ; while ( reader == null ) { getLogger ( ) . info ( "attempting to load file: " + getFileURL ( ) ) ; try { reader = new InputStreamReader ( new URL ( getFileURL ( ) ) . openStream ( ) ) ; } catch ( FileNotFoundException fnfe ) { getLogger ( ) . info ( "file not available - will try again" ) ; synchronized ( this ) { try { wait ( MISSING_FILE_RETRY_MILLIS ) ; } catch ( InterruptedException ie ) { } } } catch ( IOException ioe ) { getLogger ( ) . warn ( "unable to load file" , ioe ) ; return ; } } try { BufferedReader bufferedReader = new BufferedReader ( reader ) ; createPattern ( ) ; do { process ( bufferedReader ) ; try { synchronized ( this ) { wait ( waitMillis ) ; } } catch ( InterruptedException ie ) { } if ( tailing ) { getLogger ( ) . debug ( "tailing file" ) ; } } while ( tailing ) ; } catch ( IOException ioe ) { getLogger ( ) . info ( "stream closed" ) ; } getLogger ( ) . debug ( "processing " + path + " complete" ) ; shutdown ( ) ; } } ; if ( useCurrentThread ) { runnable . run ( ) ; } else { new Thread ( runnable , "LogFilePatternReceiver-" + getName ( ) ) . start ( ) ; } }
Read and process the log file .
2,605
protected void firePropertyChange ( final String propertyName , final Object oldVal , final Object newVal ) { propertySupport . firePropertyChange ( propertyName , oldVal , newVal ) ; }
Send property change notification to attached listeners .
2,606
public void activateOptions ( ) { super . activateOptions ( ) ; PatternConverter dtc = getDatePatternConverter ( ) ; if ( dtc == null ) { throw new IllegalStateException ( "FileNamePattern [" + getFileNamePattern ( ) + "] does not contain a valid date format specifier" ) ; } long n = System . currentTimeMillis ( ) ; StringBuffer buf = new StringBuffer ( ) ; formatFileName ( new Date ( n ) , buf ) ; lastFileName = buf . toString ( ) ; suffixLength = 0 ; if ( lastFileName . endsWith ( ".gz" ) ) { suffixLength = 3 ; } else if ( lastFileName . endsWith ( ".zip" ) ) { suffixLength = 4 ; } }
Prepares instance of use .
2,607
public void log ( final StatusData data ) { if ( ! filtered ( data ) ) { stream . println ( data . getFormattedStatus ( ) ) ; } }
Writes status messages to the console .
2,608
public static boolean execute ( final File source , final File destination , boolean renameEmptyFiles ) { if ( renameEmptyFiles || ( source . length ( ) > 0 ) ) { return source . renameTo ( destination ) ; } return source . delete ( ) ; }
Rename file .
2,609
public static Rule getRule ( final Stack stack ) { if ( stack . size ( ) < 1 ) { throw new IllegalArgumentException ( "Invalid EXISTS rule - expected one parameter but received " + stack . size ( ) ) ; } return new ExistsRule ( stack . pop ( ) . toString ( ) ) ; }
Create an instance of ExistsRule using the top name on the stack .
2,610
public void setTransform ( final Document xsltdoc ) throws TransformerConfigurationException { String encodingName = null ; mediaType = null ; String method = null ; NodeList nodes = xsltdoc . getElementsByTagNameNS ( XSLT_NS , "output" ) ; for ( int i = 0 ; i < nodes . getLength ( ) ; i ++ ) { Element outputElement = ( Element ) nodes . item ( i ) ; if ( method == null || method . length ( ) == 0 ) { method = outputElement . getAttributeNS ( null , "method" ) ; } if ( encodingName == null || encodingName . length ( ) == 0 ) { encodingName = outputElement . getAttributeNS ( null , "encoding" ) ; } if ( mediaType == null || mediaType . length ( ) == 0 ) { mediaType = outputElement . getAttributeNS ( null , "media-type" ) ; } } if ( mediaType == null || mediaType . length ( ) == 0 ) { if ( "html" . equals ( method ) ) { mediaType = "text/html" ; } else if ( "xml" . equals ( method ) ) { mediaType = "text/xml" ; } else { mediaType = "text/plain" ; } } if ( encodingName == null || encodingName . length ( ) == 0 ) { Element transformElement = xsltdoc . getDocumentElement ( ) ; Element outputElement = xsltdoc . createElementNS ( XSLT_NS , "output" ) ; outputElement . setAttributeNS ( null , "encoding" , "US-ASCII" ) ; transformElement . insertBefore ( outputElement , transformElement . getFirstChild ( ) ) ; encoding = Charset . forName ( "US-ASCII" ) ; } else { encoding = Charset . forName ( encodingName ) ; } DOMSource transformSource = new DOMSource ( xsltdoc ) ; templates = transformerFactory . newTemplates ( transformSource ) ; }
Sets XSLT transform .
2,611
public static void setOutputStream ( final OutputStream out ) { LowLevelLogUtil . writer = new PrintWriter ( Objects . requireNonNull ( out ) , true ) ; }
Sets the underlying OutputStream where exceptions are printed to .
2,612
public static void setWriter ( final Writer writer ) { LowLevelLogUtil . writer = new PrintWriter ( Objects . requireNonNull ( writer ) , true ) ; }
Sets the underlying Writer where exceptions are printed to .
2,613
public void setTimeZone ( final String s ) { if ( s == null ) { calendar = Calendar . getInstance ( ) ; } else { calendar = Calendar . getInstance ( TimeZone . getTimeZone ( s ) ) ; } }
Set timezone .
2,614
public static Rule getRule ( final Stack stack ) { if ( stack . size ( ) < 2 ) { throw new IllegalArgumentException ( "Invalid AND rule - expected two rules but received " + stack . size ( ) ) ; } Object o2 = stack . pop ( ) ; Object o1 = stack . pop ( ) ; if ( ( o2 instanceof Rule ) && ( o1 instanceof Rule ) ) { Rule p2 = ( Rule ) o2 ; Rule p1 = ( Rule ) o1 ; return new AndRule ( p1 , p2 ) ; } throw new IllegalArgumentException ( "Invalid AND rule: " + o2 + "..." + o1 ) ; }
Create rule from top two elements of stack .
2,615
public boolean isInRange ( final Level minLevel , final Level maxLevel ) { return this . intLevel >= minLevel . intLevel && this . intLevel <= maxLevel . intLevel ; }
Compares this level against the levels passed as arguments and returns true if this level is in between the given levels .
2,616
public static Level forName ( final String name , final int intValue ) { final Level level = LEVELS . get ( name ) ; if ( level != null ) { return level ; } try { return new Level ( name , intValue ) ; } catch ( final IllegalStateException ex ) { return LEVELS . get ( name ) ; } }
Retrieves an existing Level or creates on if it didn t previously exist .
2,617
public static Level [ ] values ( ) { final Collection < Level > values = Level . LEVELS . values ( ) ; return values . toArray ( new Level [ values . size ( ) ] ) ; }
Return an array of all the Levels that have been registered .
2,618
public static Level valueOf ( final String name ) { Objects . requireNonNull ( name , "No level name given." ) ; final String levelName = toUpperCase ( name ) ; final Level level = LEVELS . get ( levelName ) ; if ( level != null ) { return level ; } throw new IllegalArgumentException ( "Unknown level constant [" + levelName + "]." ) ; }
Return the Level associated with the name .
2,619
public Object [ ] getParameters ( ) { final Object [ ] result = new Object [ data . size ( ) ] ; for ( int i = 0 ; i < data . size ( ) ; i ++ ) { result [ i ] = data . getValueAt ( i ) ; } return result ; }
Returns the data elements as if they were parameters on the logging event .
2,620
@ SuppressWarnings ( "unchecked" ) public Map < String , V > getData ( ) { final TreeMap < String , V > result = new TreeMap < > ( ) ; for ( int i = 0 ; i < data . size ( ) ; i ++ ) { result . put ( data . getKeyAt ( i ) , ( V ) data . getValueAt ( i ) ) ; } return Collections . unmodifiableMap ( result ) ; }
Returns the message data as an unmodifiable Map .
2,621
public void putAll ( final Map < String , String > map ) { for ( final Map . Entry < String , ? > entry : map . entrySet ( ) ) { data . putValue ( entry . getKey ( ) , entry . getValue ( ) ) ; } }
Adds all the elements from the specified Map .
2,622
public String remove ( final String key ) { final String result = data . getValue ( key ) ; data . remove ( key ) ; return result ; }
Removes the element with the specified name .
2,623
public void asXml ( final StringBuilder sb ) { sb . append ( "<Map>\n" ) ; for ( int i = 0 ; i < data . size ( ) ; i ++ ) { sb . append ( " <Entry key=\"" ) . append ( data . getKeyAt ( i ) ) . append ( "\">" ) . append ( ( String ) data . getValueAt ( i ) ) . append ( "</Entry>\n" ) ; } sb . append ( "</Map>" ) ; }
Formats this message as an XML fragment String into the given builder .
2,624
@ SuppressWarnings ( "unchecked" ) public M newInstance ( final Map < String , V > map ) { return ( M ) new MapMessage < > ( map ) ; }
Constructs a new instance based on an existing Map .
2,625
@ SuppressWarnings ( "unchecked" ) public M with ( final String key , final String value ) { put ( key , value ) ; return ( M ) this ; }
Adds an item to the data Map in fluent style .
2,626
public void logMessage ( final String fqcn , final Level level , final Marker marker , final Message message , final Throwable t ) { logger . logMessage ( fqcn , level , marker , message , t ) ; }
Always log an event . This tends to be already guarded by an enabled check so this method should not check for the logger level again
2,627
public static Object put ( String key , Object val ) { return LoggerProviders . PROVIDER . putMdc ( key , val ) ; }
Puts the value onto the context .
2,628
public static Rule getRule ( final String expression , final boolean isPostFix ) { String postFix = expression ; if ( ! isPostFix ) { postFix = CONVERTER . convert ( expression ) ; } return new ExpressionRule ( COMPILER . compileExpression ( postFix ) ) ; }
Get rule .
2,629
public static UtilLoggingLevel toLevel ( final int val , final UtilLoggingLevel defaultLevel ) { switch ( val ) { case SEVERE_INT : return SEVERE ; case WARNING_INT : return WARNING ; case INFO_INT : return INFO ; case CONFIG_INT : return CONFIG ; case FINE_INT : return FINE ; case FINER_INT : return FINER ; case FINEST_INT : return FINEST ; default : return defaultLevel ; } }
Convert an integer passed as argument to a level . If the conversion fails then this method returns the specified default .
2,630
public static List getAllPossibleLevels ( ) { ArrayList list = new ArrayList ( ) ; list . add ( FINE ) ; list . add ( FINER ) ; list . add ( FINEST ) ; list . add ( INFO ) ; list . add ( CONFIG ) ; list . add ( WARNING ) ; list . add ( SEVERE ) ; return list ; }
Gets list of supported levels .
2,631
public static Level toLevel ( final String sArg , final Level defaultLevel ) { if ( sArg == null ) { return defaultLevel ; } String s = sArg . toUpperCase ( ) ; if ( s . equals ( "SEVERE" ) ) { return SEVERE ; } if ( s . equals ( "WARNING" ) ) { return WARNING ; } if ( s . equals ( "INFO" ) ) { return INFO ; } if ( s . equals ( "CONFI" ) ) { return CONFIG ; } if ( s . equals ( "FINE" ) ) { return FINE ; } if ( s . equals ( "FINER" ) ) { return FINER ; } if ( s . equals ( "FINEST" ) ) { return FINEST ; } return defaultLevel ; }
Get level with specified symbolic name .
2,632
public static PaxOsgiAppender createAppender ( @ PluginAttribute ( "name" ) final String name , @ PluginAttribute ( "filter" ) final String filter , final Configuration config ) { if ( name == null ) { StatusLogger . getLogger ( ) . error ( "No name provided for PaxOsgiAppender" ) ; return null ; } return new PaxOsgiAppender ( name , filter ) ; }
Create a Pax Osgi Appender .
2,633
private void updateConfiguration ( BundleContext bundleContext , final String pattern ) throws IOException { final ConfigurationAdmin configAdmin = getConfigurationAdmin ( bundleContext ) ; final Configuration configuration = configAdmin . getConfiguration ( "org.ops4j.pax.logging" , null ) ; final Hashtable < String , Object > log4jProps = new Hashtable < String , Object > ( ) ; log4jProps . put ( "log4j.rootLogger" , "DEBUG, CONSOLE" ) ; log4jProps . put ( "log4j.appender.CONSOLE" , "org.apache.log4j.ConsoleAppender" ) ; log4jProps . put ( "log4j.appender.CONSOLE.layout" , "org.apache.log4j.PatternLayout" ) ; log4jProps . put ( "log4j.appender.CONSOLE.layout.ConversionPattern" , pattern ) ; configuration . update ( log4jProps ) ; }
Updates Pax Logging configuration to a specifid conversion pattern .
2,634
private ConfigurationAdmin getConfigurationAdmin ( final BundleContext bundleContext ) { final ServiceReference ref = bundleContext . getServiceReference ( ConfigurationAdmin . class . getName ( ) ) ; if ( ref == null ) { throw new IllegalStateException ( "Cannot find a configuration admin service" ) ; } return ( ConfigurationAdmin ) bundleContext . getService ( ref ) ; }
Gets Configuration Admin service from service registry .
2,635
public void removeListener ( final StatusListener listener ) { closeSilently ( listener ) ; listenersLock . writeLock ( ) . lock ( ) ; try { listeners . remove ( listener ) ; int lowest = Level . toLevel ( DEFAULT_STATUS_LEVEL , Level . WARN ) . intLevel ( ) ; for ( final StatusListener statusListener : listeners ) { final int level = statusListener . getStatusLevel ( ) . intLevel ( ) ; if ( lowest < level ) { lowest = level ; } } listenersLevel = lowest ; } finally { listenersLock . writeLock ( ) . unlock ( ) ; } }
Removes a StatusListener .
2,636
public void reset ( ) { listenersLock . writeLock ( ) . lock ( ) ; try { for ( final StatusListener listener : listeners ) { closeSilently ( listener ) ; } } finally { listeners . clear ( ) ; listenersLock . writeLock ( ) . unlock ( ) ; clear ( ) ; } }
Clears the list of status events and listeners .
2,637
public void logMessage ( final String fqcn , final Level level , final Marker marker , final Message msg , final Throwable t ) { StackTraceElement element = null ; if ( fqcn != null ) { element = getStackTraceElement ( fqcn , Thread . currentThread ( ) . getStackTrace ( ) ) ; } final StatusData data = new StatusData ( element , level , msg , t , null ) ; msgLock . lock ( ) ; try { messages . add ( data ) ; } finally { msgLock . unlock ( ) ; } if ( isDebugPropertyEnabled ( ) ) { logger . logMessage ( fqcn , level , marker , msg , t ) ; } else { if ( listeners . size ( ) > 0 ) { for ( final StatusListener listener : listeners ) { if ( data . getLevel ( ) . isMoreSpecificThan ( listener . getStatusLevel ( ) ) ) { listener . log ( data ) ; } } } else { logger . logMessage ( fqcn , level , marker , msg , t ) ; } } }
Adds an event .
2,638
public void format ( final int fieldStart , final StringBuffer buffer ) { final int rawLength = buffer . length ( ) - fieldStart ; if ( rawLength > maxLength ) { if ( rightTruncate ) { buffer . setLength ( fieldStart + maxLength ) ; } else { buffer . delete ( fieldStart , buffer . length ( ) - maxLength ) ; } } else if ( rawLength < minLength ) { if ( leftAlign ) { final int fieldEnd = buffer . length ( ) ; buffer . setLength ( fieldStart + minLength ) ; for ( int i = fieldEnd ; i < buffer . length ( ) ; i ++ ) { buffer . setCharAt ( i , ' ' ) ; } } else { int padLength = minLength - rawLength ; for ( ; padLength > 8 ; padLength -= 8 ) { buffer . insert ( fieldStart , SPACES ) ; } buffer . insert ( fieldStart , SPACES , 0 , padLength ) ; } } }
Adjust the content of the buffer based on the specified lengths and alignment .
2,639
public static < T > T newCheckedInstanceOf ( final String className , final Class < T > clazz ) throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , InstantiationException , IllegalAccessException { return clazz . cast ( newInstanceOf ( className ) ) ; }
Loads and instantiates a derived class using its default constructor .
2,640
public static < T > T newCheckedInstanceOfProperty ( final String propertyName , final Class < T > clazz ) throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , InstantiationException , IllegalAccessException { final String className = PropertiesUtil . getProperties ( ) . getStringProperty ( propertyName ) ; if ( className == null ) { return null ; } return newCheckedInstanceOf ( className , clazz ) ; }
Loads and instantiates a class given by a property name .
2,641
public void addPlugin ( final Plugin plugin ) { synchronized ( pluginMap ) { String name = plugin . getName ( ) ; plugin . setLoggerRepository ( getLoggerRepository ( ) ) ; Plugin existingPlugin = ( Plugin ) pluginMap . get ( name ) ; if ( existingPlugin != null ) { existingPlugin . shutdown ( ) ; } pluginMap . put ( name , plugin ) ; firePluginStarted ( plugin ) ; } }
Adds a plugin to the plugin registry . If a plugin with the same name exists already it is shutdown and removed .
2,642
private void firePluginStarted ( final Plugin plugin ) { PluginEvent e = null ; synchronized ( listenerList ) { for ( Iterator iter = listenerList . iterator ( ) ; iter . hasNext ( ) ; ) { PluginListener l = ( PluginListener ) iter . next ( ) ; if ( e == null ) { e = new PluginEvent ( plugin ) ; } l . pluginStarted ( e ) ; } } }
Calls the pluginStarted method on every registered PluginListener .
2,643
private void firePluginStopped ( final Plugin plugin ) { PluginEvent e = null ; synchronized ( listenerList ) { for ( Iterator iter = listenerList . iterator ( ) ; iter . hasNext ( ) ; ) { PluginListener l = ( PluginListener ) iter . next ( ) ; if ( e == null ) { e = new PluginEvent ( plugin ) ; } l . pluginStopped ( e ) ; } } }
Calls the pluginStopped method for every registered PluginListner .
2,644
public List getPlugins ( ) { synchronized ( pluginMap ) { List pluginList = new ArrayList ( pluginMap . size ( ) ) ; Iterator iter = pluginMap . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { pluginList . add ( iter . next ( ) ) ; } return pluginList ; } }
Returns all the plugins for a given repository .
2,645
public List getPlugins ( final Class pluginClass ) { synchronized ( pluginMap ) { List pluginList = new ArrayList ( pluginMap . size ( ) ) ; Iterator iter = pluginMap . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object plugin = iter . next ( ) ; if ( pluginClass . isInstance ( plugin ) ) { pluginList . add ( plugin ) ; } } return pluginList ; } }
Returns all the plugins for a given repository that are instances of a certain class .
2,646
public Plugin stopPlugin ( final String pluginName ) { synchronized ( pluginMap ) { Plugin plugin = ( Plugin ) pluginMap . get ( pluginName ) ; if ( plugin == null ) { return null ; } plugin . shutdown ( ) ; pluginMap . remove ( pluginName ) ; firePluginStopped ( plugin ) ; return plugin ; } }
Stops a plugin by plugin name and repository .
2,647
public void stopAllPlugins ( ) { synchronized ( pluginMap ) { loggerRepository . removeLoggerRepositoryEventListener ( listener ) ; Iterator iter = pluginMap . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Plugin plugin = ( Plugin ) iter . next ( ) ; plugin . shutdown ( ) ; firePluginStopped ( plugin ) ; } } }
Stops all plugins in the given logger repository .
2,648
public void removeAppender ( String name ) { if ( name == null ) return ; for ( Iterator < Appender > it = appenderList . iterator ( ) ; it . hasNext ( ) ; ) { if ( name . equals ( it . next ( ) . getName ( ) ) ) { it . remove ( ) ; break ; } } }
Remove the appender with the name passed as parameter form the list of appenders .
2,649
protected void catching ( final String fqcn , final Level level , final Throwable t ) { if ( isEnabled ( level , CATCHING_MARKER , ( Object ) null , null ) ) { logMessageSafely ( fqcn , level , CATCHING_MARKER , catchingMsg ( t ) , t ) ; } }
Logs a Throwable that has been caught with location information .
2,650
protected < R > R exit ( final String fqcn , final R result ) { logIfEnabled ( fqcn , Level . TRACE , EXIT_MARKER , exitMsg ( null , result ) , null ) ; return result ; }
Logs exiting from a method with the result and location information .
2,651
protected < T extends Throwable > T throwing ( final String fqcn , final Level level , final T t ) { if ( isEnabled ( level , THROWING_MARKER , ( Object ) null , null ) ) { logMessageSafely ( fqcn , level , THROWING_MARKER , throwingMsg ( t ) , t ) ; } return t ; }
Logs a Throwable to be thrown .
2,652
public LogEvent createEvent ( final String loggerName , final Marker marker , final String fqcn , final Level level , final Message message , final List < Property > properties , final Throwable t ) { WeakReference < MutableLogEvent > refResult = mutableLogEventThreadLocal . get ( ) ; MutableLogEvent result = refResult == null ? null : refResult . get ( ) ; if ( result == null || result . reserved ) { final boolean initThreadLocal = result == null ; result = new MutableLogEvent ( ) ; result . setThreadId ( Thread . currentThread ( ) . getId ( ) ) ; result . setThreadName ( Thread . currentThread ( ) . getName ( ) ) ; result . setThreadPriority ( Thread . currentThread ( ) . getPriority ( ) ) ; if ( initThreadLocal ) { refResult = new WeakReference < > ( result ) ; mutableLogEventThreadLocal . set ( refResult ) ; } } result . reserved = true ; result . clear ( ) ; result . setLoggerName ( loggerName ) ; result . setMarker ( marker ) ; result . setLoggerFqcn ( fqcn ) ; result . setLevel ( level == null ? Level . OFF : level ) ; result . setMessage ( message ) ; result . setThrown ( t ) ; result . setContextData ( injector . injectContextData ( properties , ( StringMap ) result . getContextData ( ) ) ) ; result . setContextStack ( ThreadContext . getDepth ( ) == 0 ? ThreadContext . EMPTY_STACK : ThreadContext . cloneStack ( ) ) ; result . setTimeMillis ( message instanceof TimestampMessage ? ( ( TimestampMessage ) message ) . getTimestamp ( ) : CLOCK . currentTimeMillis ( ) ) ; result . setNanoTime ( Log4jLogEvent . getNanoClock ( ) . nanoTime ( ) ) ; if ( THREAD_NAME_CACHING_STRATEGY == ThreadNameCachingStrategy . UNCACHED ) { result . setThreadName ( Thread . currentThread ( ) . getName ( ) ) ; result . setThreadPriority ( Thread . currentThread ( ) . getPriority ( ) ) ; } return result ; }
Creates a log event .
2,653
public boolean execute ( ) throws IOException { if ( stopOnError ) { for ( int i = 0 ; i < actions . length ; i ++ ) { if ( ! actions [ i ] . execute ( ) ) { return false ; } } return true ; } else { boolean status = true ; IOException exception = null ; for ( int i = 0 ; i < actions . length ; i ++ ) { try { status &= actions [ i ] . execute ( ) ; } catch ( IOException ex ) { status = false ; if ( exception == null ) { exception = ex ; } } } if ( exception != null ) { throw exception ; } return status ; } }
Execute sequence of actions .
2,654
public void run ( ) { LoggingEvent event ; Logger remoteLogger ; Exception listenerException = null ; ObjectInputStream ois = null ; try { ois = new ObjectInputStream ( new BufferedInputStream ( socket . getInputStream ( ) ) ) ; } catch ( Exception e ) { ois = null ; listenerException = e ; getLogger ( ) . error ( "Exception opening ObjectInputStream to " + socket , e ) ; } if ( ois != null ) { String hostName = socket . getInetAddress ( ) . getHostName ( ) ; String remoteInfo = hostName + ":" + socket . getPort ( ) ; fireSocketOpened ( remoteInfo ) ; try { while ( ! isClosed ( ) ) { event = ( LoggingEvent ) ois . readObject ( ) ; event . setProperty ( Constants . HOSTNAME_KEY , hostName ) ; event . setProperty ( "log4j.remoteSourceInfo" , remoteInfo ) ; if ( ! isPaused ( ) && ! isClosed ( ) ) { if ( ( receiver != null ) ) { receiver . doPost ( event ) ; } else { remoteLogger = repository . getLogger ( event . getLoggerName ( ) ) ; if ( event . getLevel ( ) . isGreaterOrEqual ( remoteLogger . getEffectiveLevel ( ) ) ) { remoteLogger . callAppenders ( event ) ; } } } else { } } } catch ( java . io . EOFException e ) { getLogger ( ) . info ( "Caught java.io.EOFException closing connection." ) ; listenerException = e ; } catch ( java . net . SocketException e ) { getLogger ( ) . info ( "Caught java.net.SocketException closing connection." ) ; listenerException = e ; } catch ( IOException e ) { getLogger ( ) . info ( "Caught java.io.IOException: " + e ) ; getLogger ( ) . info ( "Closing connection." ) ; listenerException = e ; } catch ( Exception e ) { getLogger ( ) . error ( "Unexpected exception. Closing connection." , e ) ; listenerException = e ; } } try { if ( ois != null ) { ois . close ( ) ; } } catch ( Exception e ) { } if ( listenerList . size ( ) > 0 && ! isClosed ( ) ) { fireSocketClosedEvent ( listenerException ) ; } }
Deserialize events from socket until interrupted .
2,655
private void fireSocketClosedEvent ( final Exception listenerException ) { synchronized ( listenerList ) { for ( Iterator iter = listenerList . iterator ( ) ; iter . hasNext ( ) ; ) { SocketNodeEventListener snel = ( SocketNodeEventListener ) iter . next ( ) ; if ( snel != null ) { snel . socketClosedEvent ( listenerException ) ; } } } }
Notifies all registered listeners regarding the closing of the Socket .
2,656
private void fireSocketOpened ( final String remoteInfo ) { synchronized ( listenerList ) { for ( Iterator iter = listenerList . iterator ( ) ; iter . hasNext ( ) ; ) { SocketNodeEventListener snel = ( SocketNodeEventListener ) iter . next ( ) ; if ( snel != null ) { snel . socketOpened ( remoteInfo ) ; } } } }
Notifies all registered listeners regarding the opening of a Socket .
2,657
public void close ( ) throws IOException { getLogger ( ) . debug ( "closing socket" ) ; this . closed = true ; socket . close ( ) ; fireSocketClosedEvent ( null ) ; }
Close the node and underlying socket
2,658
public void setName ( final String newName ) { String oldName = this . name ; this . name = newName ; propertySupport . firePropertyChange ( "name" , oldName , this . name ) ; }
Sets the name of the plugin and notifies PropertyChangeListeners of the change .
2,659
public void setLoggerRepository ( final LoggerRepository repository ) { Object oldValue = this . repository ; this . repository = repository ; firePropertyChange ( "loggerRepository" , oldValue , this . repository ) ; }
Sets the logger repository used by this plugin and notifies a relevant PropertyChangeListeners registered . This repository will be used by the plugin functionality .
2,660
public boolean isEquivalent ( final Plugin testPlugin ) { return ( repository == testPlugin . getLoggerRepository ( ) ) && ( ( this . name == null && testPlugin . getName ( ) == null ) || ( this . name != null && name . equals ( testPlugin . getName ( ) ) ) ) && this . getClass ( ) . equals ( testPlugin . getClass ( ) ) ; }
Returns true if the plugin has the same name and logger repository as the testPlugin passed in .
2,661
protected final void firePropertyChange ( final String propertyName , final Object oldValue , final Object newValue ) { propertySupport . firePropertyChange ( propertyName , oldValue , newValue ) ; }
Fire property change event to appropriate listeners .
2,662
private synchronized void closeAllAcceptedSockets ( ) { for ( int x = 0 ; x < socketList . size ( ) ; x ++ ) { try { ( ( Socket ) socketList . get ( x ) ) . close ( ) ; } catch ( Exception e ) { } } socketMap . clear ( ) ; socketList . clear ( ) ; }
Closes all the connected sockets in the List .
2,663
public boolean contains ( String name ) { if ( name == null ) { throw new IllegalArgumentException ( "Other cannot be null" ) ; } if ( this . name . equals ( name ) ) { return true ; } if ( hasReferences ( ) ) { for ( Marker ref : referenceList ) { if ( ref . contains ( name ) ) { return true ; } } } return false ; }
This method is mainly used with Expression Evaluators .
2,664
public static CloseableThreadContext . Instance push ( final String message , final Object ... args ) { return new CloseableThreadContext . Instance ( ) . push ( message , args ) ; }
Pushes new diagnostic context information on to the Thread Context Stack . The information will be popped off when the instance is closed .
2,665
public static CloseableThreadContext . Instance pushAll ( final List < String > messages ) { return new CloseableThreadContext . Instance ( ) . pushAll ( messages ) ; }
Populates the Thread Context Stack with the supplied stack . The information will be popped off when the instance is closed .
2,666
public static void logEvent ( final StructuredDataMessage msg ) { LOGGER . logIfEnabled ( FQCN , Level . OFF , EVENT_MARKER , msg , null ) ; }
Logs events with a level of ALL .
2,667
public void trace ( Object message ) { doLog ( Level . TRACE , FQCN , message , null , null ) ; }
Issue a log message with a level of TRACE .
2,668
public void trace ( Object message , Throwable t ) { doLog ( Level . TRACE , FQCN , message , null , t ) ; }
Issue a log message and throwable with a level of TRACE .
2,669
public void trace ( Object message , Object [ ] params ) { doLog ( Level . TRACE , FQCN , message , params , null ) ; }
Issue a log message with parameters with a level of TRACE .
2,670
public void debug ( Object message ) { doLog ( Level . DEBUG , FQCN , message , null , null ) ; }
Issue a log message with a level of DEBUG .
2,671
public void debug ( Object message , Throwable t ) { doLog ( Level . DEBUG , FQCN , message , null , t ) ; }
Issue a log message and throwable with a level of DEBUG .
2,672
public void debug ( String loggerFqcn , Object message , Throwable t ) { doLog ( Level . DEBUG , loggerFqcn , message , null , t ) ; }
Issue a log message and throwable with a level of DEBUG and a specific logger class name .
2,673
public void debug ( Object message , Object [ ] params ) { doLog ( Level . DEBUG , FQCN , message , params , null ) ; }
Issue a log message with parameters with a level of DEBUG .
2,674
public void debug ( Object message , Object [ ] params , Throwable t ) { doLog ( Level . DEBUG , FQCN , message , params , t ) ; }
Issue a log message with parameters and a throwable with a level of DEBUG .
2,675
public void info ( Object message ) { doLog ( Level . INFO , FQCN , message , null , null ) ; }
Issue a log message with a level of INFO .
2,676
public void info ( Object message , Throwable t ) { doLog ( Level . INFO , FQCN , message , null , t ) ; }
Issue a log message and throwable with a level of INFO .
2,677
public void info ( String loggerFqcn , Object message , Throwable t ) { doLog ( Level . INFO , loggerFqcn , message , null , t ) ; }
Issue a log message and throwable with a level of INFO and a specific logger class name .
2,678
public void info ( Object message , Object [ ] params ) { doLog ( Level . INFO , FQCN , message , params , null ) ; }
Issue a log message with parameters with a level of INFO .
2,679
public void info ( Object message , Object [ ] params , Throwable t ) { doLog ( Level . INFO , FQCN , message , params , t ) ; }
Issue a log message with parameters and a throwable with a level of INFO .
2,680
public void warn ( Object message ) { doLog ( Level . WARN , FQCN , message , null , null ) ; }
Issue a log message with a level of WARN .
2,681
public void warn ( Object message , Throwable t ) { doLog ( Level . WARN , FQCN , message , null , t ) ; }
Issue a log message and throwable with a level of WARN .
2,682
public void warn ( String loggerFqcn , Object message , Throwable t ) { doLog ( Level . WARN , loggerFqcn , message , null , t ) ; }
Issue a log message and throwable with a level of WARN and a specific logger class name .
2,683
public void warn ( Object message , Object [ ] params ) { doLog ( Level . WARN , FQCN , message , params , null ) ; }
Issue a log message with parameters with a level of WARN .
2,684
public void warn ( Object message , Object [ ] params , Throwable t ) { doLog ( Level . WARN , FQCN , message , params , t ) ; }
Issue a log message with parameters and a throwable with a level of WARN .
2,685
public void error ( Object message ) { doLog ( Level . ERROR , FQCN , message , null , null ) ; }
Issue a log message with a level of ERROR .
2,686
public void error ( Object message , Throwable t ) { doLog ( Level . ERROR , FQCN , message , null , t ) ; }
Issue a log message and throwable with a level of ERROR .
2,687
public void error ( Object message , Object [ ] params ) { doLog ( Level . ERROR , FQCN , message , params , null ) ; }
Issue a log message with parameters with a level of ERROR .
2,688
public void fatal ( Object message ) { doLog ( Level . FATAL , FQCN , message , null , null ) ; }
Issue a log message with a level of FATAL .
2,689
public void fatal ( Object message , Throwable t ) { doLog ( Level . FATAL , FQCN , message , null , t ) ; }
Issue a log message and throwable with a level of FATAL .
2,690
public void fatal ( Object message , Object [ ] params ) { doLog ( Level . FATAL , FQCN , message , params , null ) ; }
Issue a log message with parameters with a level of FATAL .
2,691
public void log ( Level level , String loggerFqcn , Object message , Throwable t ) { doLog ( level , loggerFqcn , message , null , t ) ; }
Issue a log message and throwable at the given log level and a specific logger class name .
2,692
public void log ( Level level , Object message , Object [ ] params ) { doLog ( level , FQCN , message , params , null ) ; }
Issue a log message with parameters at the given log level .
2,693
public void log ( Level level , Object message , Object [ ] params , Throwable t ) { doLog ( level , FQCN , message , params , t ) ; }
Issue a log message with parameters and a throwable at the given log level .
2,694
public static < T > T getMessageLogger ( Class < T > type , String category ) { return getMessageLogger ( type , category , Locale . getDefault ( ) ) ; }
Get a typed logger which implements the given interface . The current default locale will be used for the new logger .
2,695
public static < T > T getMessageLogger ( final Class < T > type , final String category , final Locale locale ) { return doPrivileged ( new PrivilegedAction < T > ( ) { public T run ( ) { String language = locale . getLanguage ( ) ; String country = locale . getCountry ( ) ; String variant = locale . getVariant ( ) ; Class < ? extends T > loggerClass = null ; final ClassLoader classLoader = type . getClassLoader ( ) ; final String typeName = type . getName ( ) ; if ( variant != null && variant . length ( ) > 0 ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , language , country , variant ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { } if ( loggerClass == null && country != null && country . length ( ) > 0 ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , language , country , null ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { } if ( loggerClass == null && language != null && language . length ( ) > 0 ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , language , null , null ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { } if ( loggerClass == null ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , null , null , null ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { throw new IllegalArgumentException ( "Invalid logger " + type + " (implementation not found in " + classLoader + ")" ) ; } final Constructor < ? extends T > constructor ; try { constructor = loggerClass . getConstructor ( Logger . class ) ; } catch ( NoSuchMethodException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " has no matching constructor" ) ; } try { return constructor . newInstance ( Logger . getLogger ( category ) ) ; } catch ( InstantiationException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " could not be instantiated" , e ) ; } catch ( IllegalAccessException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " could not be instantiated" , e ) ; } catch ( InvocationTargetException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " could not be instantiated" , e . getCause ( ) ) ; } } } ) ; }
Get a typed logger which implements the given interface . The given locale will be used for the new logger .
2,696
public static Rule getRule ( final String field , final String value ) { if ( field . equalsIgnoreCase ( LoggingEventFieldResolver . LEVEL_FIELD ) ) { return NotLevelEqualsRule . getRule ( value ) ; } else { return new NotEqualsRule ( field , value ) ; } }
Get new instance .
2,697
public static Rule getRule ( final Stack stack ) { if ( stack . size ( ) < 2 ) { throw new IllegalArgumentException ( "Invalid NOT EQUALS rule - expected two parameters but received " + stack . size ( ) ) ; } String p2 = stack . pop ( ) . toString ( ) ; String p1 = stack . pop ( ) . toString ( ) ; if ( p1 . equalsIgnoreCase ( LoggingEventFieldResolver . LEVEL_FIELD ) ) { return NotLevelEqualsRule . getRule ( p2 ) ; } else { return new NotEqualsRule ( p1 , p2 ) ; } }
Get new instance from top two elements of stack .
2,698
public void discoverConnnectionProperties ( ) { Connection connection = null ; try { connection = getConnection ( ) ; if ( connection == null ) { getLogger ( ) . warn ( "Could not get a conneciton" ) ; return ; } DatabaseMetaData meta = connection . getMetaData ( ) ; Util util = new Util ( ) ; util . setLoggerRepository ( repository ) ; if ( overriddenSupportsGetGeneratedKeys != null ) { supportsGetGeneratedKeys = overriddenSupportsGetGeneratedKeys . booleanValue ( ) ; } else { supportsGetGeneratedKeys = util . supportsGetGeneratedKeys ( meta ) ; } supportsBatchUpdates = util . supportsBatchUpdates ( meta ) ; dialectCode = Util . discoverSQLDialect ( meta ) ; } catch ( SQLException se ) { getLogger ( ) . warn ( "Could not discover the dialect to use." , se ) ; } finally { DBHelper . closeConnection ( connection ) ; } }
Learn relevant information about this connection source .
2,699
public String getSuppressedStackTrace ( final String suffix ) { final ThrowableProxy [ ] suppressed = this . getSuppressedProxies ( ) ; if ( suppressed == null || suppressed . length == 0 ) { return Strings . EMPTY ; } final StringBuilder sb = new StringBuilder ( "Suppressed Stack Trace Elements:" ) . append ( EOL ) ; for ( final ThrowableProxy proxy : suppressed ) { sb . append ( proxy . getExtendedStackTraceAsString ( suffix ) ) ; } return sb . toString ( ) ; }
Format the suppressed Throwables .