/*
 * The MIT License
 *
 * Copyright 2018 michael.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package il.ac.bgu.cs.bp.bpjs.execution.jsproxy;

import il.ac.bgu.cs.bp.bpjs.internal.ScriptableUtils;
import il.ac.bgu.cs.bp.bpjs.model.BProgram;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static java.util.stream.Collectors.joining;
import java.util.stream.IntStream;
import org.mozilla.javascript.ConsString;
import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.ScriptableObject;

/**
 * Simple logging mechanism for {@link BProgram}s.
 * 
 * @author michael
 */
public class BpLog implements java.io.Serializable {
    
    public enum LogLevel {
        Off, Warn, Info, Fine
    }
    LogLevel level = LogLevel.Info;

    public void warn(Object msg) {
        log(LogLevel.Warn, msg);
    }

    public void info(Object msg) {
        log(LogLevel.Info, msg);
    }

    public void fine(Object msg) {
        log(LogLevel.Fine, msg);
    }

    public void log(LogLevel lvl, Object msg) {
        if (level.compareTo(lvl) >= 0) {
            System.out.println("[BP][" + lvl.name() + "] " + ScriptableUtils.stringify(msg));
        }
    }

    public void setLevel(String levelName) {
        synchronized (this) {
            level = LogLevel.valueOf(levelName);
        }
    }

    public String getLevel() {
        return level.name();
    }
    
}

@@ -1275,317 +1275,64 @@
 am;%0A
-import java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport static java.util.stream.Collectors.joining;%0Aimport java.util.stream.IntStream;%0Aimport org.mozilla.javascript.ConsString;%0Aimport org.mozilla.javascript.NativeArray;%0Aimport org.mozilla.javascript.ScriptableObject
+%0Aimport java.text.MessageFormat;%0Aimport java.util.Arrays
 ;%0A%0A/
@@ -1593,32 +1593,48 @@
  warn(Object msg
+, Object ...args
 ) %7B%0A        log(
@@ -1647,24 +1647,30 @@
 el.Warn, msg
+, args
 );%0A    %7D%0A%0A  
@@ -1690,32 +1690,48 @@
  info(Object msg
+, Object ...args
 ) %7B%0A        log(
@@ -1744,24 +1744,30 @@
 el.Info, msg
+, args
 );%0A    %7D%0A%0A  
@@ -1787,32 +1787,48 @@
  fine(Object msg
+, Object ...args
 ) %7B%0A        log(
@@ -1845,16 +1845,22 @@
 ine, msg
+, args
 );%0A    %7D
@@ -1905,16 +1905,32 @@
 ject msg
+, Object... args
 ) %7B%0A    
@@ -2030,38 +2030,223 @@
  %22 +
- ScriptableUtils.stringify(msg
+%0A                args == null %7C%7C args.length == 0 ? ScriptableUtils.stringify(msg) :%0A                MessageFormat.format(ScriptableUtils.stringify(msg), Arrays.stream(args).map(ScriptableUtils::stringify).toArray()
 ));%0A

Support MessageFormat notation in bp logger.