/** * Add all the properties found in the argument named 'props' to an * InterpretationContext. */ static public void setProperties(InterpretationContext ic, Properties props, Scope scope) { switch (scope) { case LOCAL: ic.addSubstitutionProperties(props); break; case CONTEXT: ContextUtil cu = new ContextUtil(ic.getContext()); cu.addProperties(props); break; case SYSTEM: OptionHelper.setSystemProperties(ic, props); } }
/** * Add the local host's name as a property */ public void addHostNameAsProperty() { try { String localhostName = getLocalHostName(); context.putProperty(CoreConstants.HOSTNAME_KEY, localhostName); } catch (UnknownHostException e) { addError("Failed to get local hostname", e); } catch (SocketException e) { addError("Failed to get local hostname", e); } catch (SecurityException e) { addError("Failed to get local hostname", e); } }
public ContextUtil(Context context) { setContext(context); }
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LOGBACK-527 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); } processScanAttrib(ic, attributes); LoggerContext lc = (LoggerContext) context; boolean packagingData = OptionHelper.toBoolean(ic.subst(attributes.getValue(PACKAGING_DATA_ATTR)), LoggerContext.DEFAULT_PACKAGING_DATA); lc.setPackagingDataEnabled(packagingData); if (EnvUtil.isGroovyAvailable()) { ContextUtil contextUtil = new ContextUtil(context); contextUtil.addGroovyPackages(lc.getFrameworkPackages()); } // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LOGBACK-527 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { OnConsoleStatusListener.addNewInstanceToContext(context); } processScanAttrib(ic, attributes); ContextUtil contextUtil = new ContextUtil(context); contextUtil.addHostNameAsProperty(); if(EnvUtil.isGroovyAvailable()) { LoggerContext lc = (LoggerContext) context; contextUtil.addGroovyPackages(lc.getFrameworkPackages()); } // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
private String lazyGetHostname() { String hostname = (String) this.propertyMap.get(HOSTNAME_KEY); if (hostname == null) { hostname = new ContextUtil(this).safelyGetLocalHostName(); putHostnameProperty(hostname); } return hostname; }
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LBCLASSIC-225 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = System.getProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { OnConsoleStatusListener.addNewInstanceToContext(context); } processScanAttrib(ic, attributes); new ContextUtil(context).addHostNameAsProperty(); // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
private String getHostName() { try { return ContextUtil.getLocalHostName(); } catch (UnknownHostException|SocketException e) { return "undefined"; } }
public static String getLocalHostName() throws UnknownHostException, SocketException { try { InetAddress localhost = InetAddress.getLocalHost(); return localhost.getHostName(); } catch (UnknownHostException e) { return getLocalAddressAsString(); } }
public void addGroovyPackages(List<String> frameworkPackages) { //addFrameworkPackage(frameworkPackages, "groovy.lang"); addFrameworkPackage(frameworkPackages, "org.codehaus.groovy.runtime"); }
private static String getLocalAddressAsString() throws UnknownHostException, SocketException { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces != null && interfaces.hasMoreElements()) { Enumeration<InetAddress> addresses = interfaces.nextElement().getInetAddresses(); while (addresses != null && addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (acceptableAddress(address)) { return address.getHostAddress(); } } } throw new UnknownHostException(); }
@Override public void stop() { super.stop(); Map<String, String> map = ContextUtil.getFilenameCollisionMap(context); if (map == null || getName() == null) return; map.remove(getName()); }
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LOGBACK-527 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); } processScanAttrib(ic, attributes); LoggerContext lc = (LoggerContext) context; boolean packagingData = OptionHelper.toBoolean(ic.subst(attributes.getValue(PACKAGING_DATA_ATTR)), LoggerContext.DEFAULT_PACKAGING_DATA); lc.setPackagingDataEnabled(packagingData); if (EnvUtil.isGroovyAvailable()) { ContextUtil contextUtil = new ContextUtil(context); contextUtil.addGroovyPackages(lc.getFrameworkPackages()); } // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
private String lazyGetHostname() { String hostname = (String) this.propertyMap.get(HOSTNAME_KEY); if (hostname == null) { hostname = new ContextUtil(this).safelyGetLocalHostName(); putHostnameProperty(hostname); } return hostname; }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) { // See LBCLASSIC-225 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = OptionHelper.getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); } processScanAttrib(ic, attributes); ContextUtil contextUtil = new ContextUtil(context); contextUtil.addHostNameAsProperty(); // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); LoggerContext lc = (LoggerContext) context; boolean packagingData = OptionHelper.toBoolean( ic.subst(attributes.getValue(PACKAGING_DATA_ATTR)), LoggerContext.DEFAULT_PACKAGING_DATA); lc.setPackagingDataEnabled(packagingData); }
public String getHostName() { try { return ContextUtil.getLocalHostName(); } catch (Exception e) { // ignored } return null; }
public static String getLocalHostName() throws UnknownHostException, SocketException { try { InetAddress localhost = InetAddress.getLocalHost(); return localhost.getHostName(); } catch (UnknownHostException e) { return getLocalAddressAsString(); } }
public void addGroovyPackages(List<String> frameworkPackages) { // addFrameworkPackage(frameworkPackages, "groovy.lang"); addFrameworkPackage(frameworkPackages, "org.codehaus.groovy.runtime"); }
private static String getLocalAddressAsString() throws UnknownHostException, SocketException { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces != null && interfaces.hasMoreElements()) { Enumeration<InetAddress> addresses = interfaces.nextElement().getInetAddresses(); while (addresses != null && addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (acceptableAddress(address)) { return address.getHostAddress(); } } } throw new UnknownHostException(); }
@Override public void stop() { super.stop(); Map<String, String> map = ContextUtil.getFilenameCollisionMap(context); if (map == null || getName() == null) return; map.remove(getName()); }