<commit_before>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package org.appcelerator.kroll;

import android.util.Log;

public class KrollLogging
{
	public static final int TRACE = 1;
	public static final int DEBUG = 2;
	public static final int INFO = 3;
	public static final int NOTICE = 4;
	public static final int WARN = 5;
	public static final int ERROR = 6;
	public static final int CRITICAL = 7;
	public static final int FATAL = 8;

	private static KrollLogging instance = new KrollLogging("TiAPI");

	private String tag;
	private LogListener listener;

	public static KrollLogging getDefault()
	{
		return instance;
	}

	public static void logWithDefaultLogger(int severity, String msg)
	{
		getDefault().internalLog(severity, msg);
	}

	public interface LogListener
	{
		public void onLog(int severity, String msg);
	}

	private KrollLogging(String tag)
	{
		this.tag = tag;
	}

	public void setLogListener(LogListener listener)
	{
		this.listener = listener;
	}
	
	public void debug(String msg)
	{
		internalLog(DEBUG, msg);
	}

	public void info(String msg)
	{
		internalLog(INFO, msg);
	}

	public void warn(String msg)
	{
		internalLog(WARN, msg);
	}

	public void error(String msg)
	{
		internalLog(ERROR, msg);
	}

	public void trace(String msg)
	{
		internalLog(TRACE, msg);
	}

	public void notice(String msg)
	{
		internalLog(NOTICE, msg);
	}

	public void critical(String msg)
	{
		internalLog(CRITICAL, msg);
	}

	public void fatal(String msg)
	{
		internalLog(FATAL, msg);
	}
	
	public void log(String msg)
	{
		internalLog(INFO, msg);
	}

	public void log(String level, String msg)
	{
		String ulevel = level.toUpperCase();
		int severity = INFO;

		if ("TRACE".equals(ulevel)) {
			severity = TRACE;
		} else if ("DEBUG".equals(ulevel)) {
			severity = DEBUG;
		} else if ("INFO".equals(ulevel)) {
			severity = INFO;
		} else if ("NOTICE".equals(ulevel)) {
			severity = NOTICE;
		} else if ("WARN".equals(ulevel)) {
			severity = WARN;
		} else if ("ERROR".equals(ulevel)) {
			severity = ERROR;
		} else if ("CRITICAL".equals(ulevel)) {
			severity = CRITICAL;
		} else if ("FATAL".equals(ulevel)) {
			severity = FATAL;
		} else {
			msg = "[" + level + "] " + msg;
		}

		internalLog(severity, msg);
	}

	private void internalLog(int severity, String msg)
	{
		if (severity == TRACE)
		{
			Log.v(tag,msg);
		}
		else if (severity < INFO)
		{
			Log.d(tag,msg);
		}
		else if (severity < WARN)
		{
			Log.i(tag,msg);
		}
		else if (severity == WARN)
		{
			Log.w(tag,msg);
		}
		else
		{
			Log.e(tag,msg);
		}

		if (listener != null) {
			listener.onLog(severity, msg);
		}<commit_msg>[TIMOB-7624] Rhino support for API.* logging method varargs.<commit_after>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package org.appcelerator.kroll;

import android.util.Log;

public class KrollLogging
{
	public static final int TRACE = 1;
	public static final int DEBUG = 2;
	public static final int INFO = 3;
	public static final int NOTICE = 4;
	public static final int WARN = 5;
	public static final int ERROR = 6;
	public static final int CRITICAL = 7;
	public static final int FATAL = 8;

	private static KrollLogging instance = new KrollLogging("TiAPI");

	private String tag;
	private LogListener listener;

	public static KrollLogging getDefault()
	{
		return instance;
	}

	public static void logWithDefaultLogger(int severity, String msg)
	{
		getDefault().internalLog(severity, msg);
	}

	public interface LogListener
	{
		public void onLog(int severity, String msg);
	}

	private KrollLogging(String tag)
	{
		this.tag = tag;
	}

	public void setLogListener(LogListener listener)
	{
		this.listener = listener;
	}
	
	public void debug(String... args)
	{
		internalLog(DEBUG, condenseMessage(args));
	}

	public void info(String... args)
	{
		internalLog(INFO, condenseMessage(args));
	}

	public void warn(String... args)
	{
		internalLog(WARN, condenseMessage(args));
	}

	public void error(String... args)
	{
		internalLog(ERROR, condenseMessage(args));
	}

	public void trace(String... args)
	{
		internalLog(TRACE, condenseMessage(args));
	}

	public void notice(String... args)
	{
		internalLog(NOTICE, condenseMessage(args));
	}

	public void critical(String... args)
	{
		internalLog(CRITICAL, condenseMessage(args));
	}

	public void fatal(String... args)
	{
		internalLog(FATAL, condenseMessage(args));
	}
	
	public void log(String... args)
	{
		internalLog(INFO, condenseMessage(args));
	}

	public void log(String level, String... args)
	{
		String ulevel = level.toUpperCase();
		String msg = condenseMessage(args);
		int severity = INFO;

		if ("TRACE".equals(ulevel)) {
			severity = TRACE;
		} else if ("DEBUG".equals(ulevel)) {
			severity = DEBUG;
		} else if ("INFO".equals(ulevel)) {
			severity = INFO;
		} else if ("NOTICE".equals(ulevel)) {
			severity = NOTICE;
		} else if ("WARN".equals(ulevel)) {
			severity = WARN;
		} else if ("ERROR".equals(ulevel)) {
			severity = ERROR;
		} else if ("CRITICAL".equals(ulevel)) {
			severity = CRITICAL;
		} else if ("FATAL".equals(ulevel)) {
			severity = FATAL;
		} else {
			msg = "[" + level + "] " + msg;
		}

		internalLog(severity, msg);
	}
	
	private String condenseMessage(String... args)
	{
		String msg;
		if (args.length > 0) {
			msg = args[0];
		}
		else {
			msg = new String();
		}
		for (int i=1; i < args.length; i++ ) {
			msg = msg.concat(String.format(" %s", args[i]));
		}
		return msg;
	}

	private void internalLog(int severity, String msg)
	{
		if (severity == TRACE)
		{
			Log.v(tag,msg);
		}
		else if (severity < INFO)
		{
			Log.d(tag,msg);
		}
		else if (severity < WARN)
		{
			Log.i(tag,msg);
		}
		else if (severity == WARN)
		{
			Log.w(tag,msg);
		}
		else
		{
			Log.e(tag,msg);
		}

		if (listener != null) {
			listener.onLog(severity, msg);
		}
{'fraction_non_alphanumeric': 0.12785980853480447, 'fraction_numerical': 0.006328086970631186, 'mean_word_length': 3.4829090909090907, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1374798', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2124, 'n_words': 591}