diff options
Diffstat (limited to 'plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java')
-rw-r--r-- | plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java new file mode 100644 index 00000000..32eb4d8c --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.logging; + +import java.util.HashMap; +import java.util.Map; + +/** + * A logger with basic process handling facilities. + */ +public class Logger { + + private int processCount = 0; + private Map<Integer, Boolean> subProcesses = new HashMap<Integer, Boolean>(); + private boolean justEndedProcess = false; + + /** Log a single event */ + public void log( final String message ) { + createNewEntry( message ); + justEndedProcess = true; + } + + /** Log the beginning of an ongoing process. */ + public void logBeginProcess( final String message ) { + createNewEntry( message ); + System.out.print( "..." );//$NON-NLS-1$ + processCount++; + memorizeProcess( Boolean.FALSE ); + justEndedProcess = false; + } + + private void createNewEntry( final String message ) { + memorizeProcess( Boolean.TRUE ); + System.out.println(); + indent(); + System.out.print( message ); + } + + private void memorizeProcess( final Boolean value ) { + subProcesses.put( getProcessCount(), value ); + } + + /** Indent to indicate sub-processes. */ + private void indent() { + for( int index = 0; index < processCount; index++ ) { + System.out.print( " " ); //$NON-NLS-1$ + } + } + + public void logEndProcess( final String message ) { + if( processCount > 0 ) { + if( justEndedProcess ) { + System.out.println(); + } + boolean booleanValue = subProcesses.get( getProcessCount() ) + .booleanValue(); + processCount--; + if( booleanValue ) { + indent(); + } + System.out.print( message ); + justEndedProcess = true; + } + } + + private Integer getProcessCount() { + return Integer.valueOf( processCount ); + } +}
\ No newline at end of file |