Package org.apache.log

Examples of org.apache.log.Logger


        final Hierarchy hierarchy = new Hierarchy();
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        final StreamTarget target = new StreamTarget( output, FORMATTER );
        hierarchy.setDefaultLogTarget( target );

        final Logger b = hierarchy.getLoggerFor( "b" );
        final Logger bc = hierarchy.getLoggerFor( "b.c" );
        final Logger bcd = hierarchy.getLoggerFor( "b.c.d" );

        b.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );

        b.setPriority( Priority.WARN );
        b.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );

        bc.setPriority( Priority.DEBUG );
        b.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );

        bcd.setPriority( Priority.WARN );
        b.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );

        bcd.unsetPriority();
        b.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );

        bc.unsetPriority();
        b.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );

        b.unsetPriority();
        b.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );

        bc.setPriority( Priority.WARN );
        b.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", "", getResult( output ) );

        b.unsetPriority( true );
        b.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bc.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
        bcd.debug( MSG );
        assertEquals( "Priority debug output", RMSG, getResult( output ) );
    }
View Full Code Here


    }

    private Logger getNewLogger( final LogTarget target )
    {
        final Hierarchy hierarchy = new Hierarchy();
        final Logger logger = hierarchy.getLoggerFor( "myCategory" );
        logger.setLogTargets( new LogTarget[]{target} );
        return logger;
    }
View Full Code Here

     *
     * @see org.apache.velocity.runtime.log.LogSystem#logVelocityMessage
     */
    public void logVelocityMessage(int level, String message)
    {
        Logger logger = getLogger();
        switch (level)
  {
      case LogSystem.WARN_ID:
    logger.warn(message);
    break;
      case LogSystem.INFO_ID:
    logger.info(message);
    break;
      case LogSystem.DEBUG_ID:
    logger.debug(message);
    break;
      case LogSystem.ERROR_ID:
    logger.error(message);
    break;
      default:
    logger.info(message);
    break;
        }
    }
View Full Code Here

    protected void initManager(BSFManager mgr) throws BSFException{
        final String label = getName();
        final String fileName = getFilename();
        final String scriptParameters = getParameters();
        // Use actual class name for log
        final Logger logger = LoggingManager.getLoggerForShortName(getClass().getName());
        mgr.declareBean("log", logger, Logger.class); // $NON-NLS-1$
        mgr.declareBean("Label",label, String.class); // $NON-NLS-1$
        mgr.declareBean("FileName",fileName, String.class); // $NON-NLS-1$
        mgr.declareBean("Parameters", scriptParameters, String.class); // $NON-NLS-1$
        String [] args=JOrphanUtils.split(scriptParameters, " ");//$NON-NLS-1$
View Full Code Here

    /**
     * Return the underlying Logger we are using.
     */
    public Logger getLogger() {
        Logger result = logger;
        if (result == null) {
            synchronized(this) {
                result = logger;
                if (result == null) {
                    logger = result = Hierarchy.getDefaultHierarchy().getLoggerFor(name);
View Full Code Here

            final Configuration category = categories[ i ];
            final String name = category.getAttribute( "name", "" );
            final String target = category.getAttribute( "target" );
            final String priorityName = category.getAttribute( "priority" );

            final Logger logger =
                m_logkitLogger.getChildLogger( name );

            final LogTarget logTarget = (LogTarget)targets.get( target );
            if( null == target )
            {
                final String message =
                    "Unable to locate LogTarget named \"" + target +
                    "\" for Logger named \"" + name + "\".";
                throw new ConfigurationException( message );
            }

            final Priority priority = Priority.getPriorityForName( priorityName );
            if( !priority.getName().equals( priorityName ) )
            {
                final String message =
                    "Unknown priority \"" + priorityName + "\" for Logger named \"" +
                    name + "\".";
                throw new ConfigurationException( message );
            }

            if( getLogger().isDebugEnabled() )
            {
                final String message =
                    "Creating a log category named \"" + name +
                    "\" that writes to \"" + target + "\" target at priority \"" +
                    priorityName + "\".";
                getLogger().debug( message );
            }

            if( name.equals( "" ) )
            {
                m_logkitLogger.setPriority( priority );
                m_logkitLogger.setLogTargets( new LogTarget[] {logTarget} );
            }
            else
            {
                logger.setPriority( priority );
                logger.setLogTargets( new LogTarget[]{logTarget} );
            }
        }
    }
View Full Code Here

        //  in the <logkit> node
        String lmLoggerName = confLM.getAttribute( "logger", "lm" );
        String lmLogLevel = confLM.getAttribute( "log-level", "INFO" );
        Priority lmPriority = Priority.getPriorityForName( lmLogLevel );
        DefaultLogKitManager logKitManager = new DefaultLogKitManager();
        Logger lmLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( lmLoggerName );
        lmLogger.setPriority( lmPriority );
        logKitManager.enableLogging( new LogKitLogger( lmLogger ) );
        logKitManager.contextualize( context );
        logKitManager.configure( confLM );
        Hierarchy h = logKitManager.getHierarchy();
        h.setDefaultPriority( lmPriority );
View Full Code Here

     * @param categoryName  The category name of a configured Logger.
     * @return the Logger.
     */
    public final Logger getLogger( final String categoryName )
    {
        final Logger logger = (Logger)m_loggers.get( categoryName );

        if( null != logger )
        {
            if( getLogger().isDebugEnabled() )
            {
View Full Code Here

            else
            {
                fullCategory = parentCategory + Logger.CATEGORY_SEPARATOR + category;
            }

            final Logger logger =
                m_hierarchy.getLoggerFor( fullCategory );
            m_loggers.put( fullCategory, logger );
            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "added logger for category " + fullCategory );
            }
            logger.setPriority( Priority.getPriorityForName( loglevel ) );
            logger.setLogTargets( logTargets );

            final Configuration[] subCategories = categories[ i ].getChildren( "category" );
            if( null != subCategories )
            {
                setupLoggers( targetManager, fullCategory, subCategories );
View Full Code Here

  public static void setPriority(Priority p) {
    Hierarchy.getDefaultHierarchy().setDefaultPriority(p);
  }

  public static void setTarget(LogTarget target, String category) {
    Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor(category);
    logger.setLogTargets(new LogTarget[] { target });
  }
View Full Code Here

TOP

Related Classes of org.apache.log.Logger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.