001    // --- BEGIN LICENSE BLOCK ---
002    /*
003     * Copyright (c) 2009, Mikio L. Braun
004     * All rights reserved.
005     *
006     * Redistribution and use in source and binary forms, with or without
007     * modification, are permitted provided that the following conditions are
008     * met:
009     *
010     *     * Redistributions of source code must retain the above copyright
011     *       notice, this list of conditions and the following disclaimer.
012     *
013     *     * Redistributions in binary form must reproduce the above
014     *       copyright notice, this list of conditions and the following
015     *       disclaimer in the documentation and/or other materials provided
016     *       with the distribution.
017     *
018     *     * Neither the name of the Technische Universit??t Berlin nor the
019     *       names of its contributors may be used to endorse or promote
020     *       products derived from this software without specific prior
021     *       written permission.
022     *
023     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027     * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034     */
035    // --- END LICENSE BLOCK ---
036    
037    package org.jblas.util;
038    
039    /**
040     *
041     */
042    public class Logger {
043        public static final int ERROR = 5;
044        public static final int WARNING = 4;
045        public static final int INFO = 3;
046        public static final int CONFIG = 2;
047        public static final int DEBUG = 1;
048    
049        public static final String levelNames[] = {
050            "DEBUG", "CONFIG", "INFO", "WARNING", "ERROR"
051        };
052    
053        private static Logger theLogger = new Logger();
054        private int level;
055    
056        private Logger() {
057            level = INFO;
058        }
059    
060        public static Logger getLogger() {
061            return theLogger;
062        }
063    
064        public void log(int messageLevel, String msg) {
065            if (level <= messageLevel) {
066                System.err.println("-- org.jblas " + levelNames[messageLevel - 1] + " "+ msg);
067            }
068        }
069    
070        public void debug(String msg) {
071            log(DEBUG, msg);
072        }
073    
074        public void config(String msg) {
075            log(CONFIG, msg);
076        }
077    
078        public void info(String msg) {
079            log(INFO, msg);
080        }
081    
082        public void warning(String msg) {
083            log(WARNING, msg);
084        }
085    
086        public void error(String msg) {
087            log(ERROR, msg);
088        }
089    
090        public void setLevel(int level) {
091            this.level = level;
092        }
093    }