using System;

namespace extc {
public class Log {
  public enum Level {
    DBG = 0,
    INF = 1,
    WRN = 2,
    ERR = 3,
  }
  
  public delegate void Callback( Level level, String msg );
  
  protected static Callback s_callback;
  
  public static Callback callback( Callback new_callback ){
    Callback old_callback = s_callback;
    s_callback = new_callback;
    return old_callback;
  }
  
  public static void write( Level level, String msg ){
    s_callback( level, msg );
  }
  
  public static void printf( Level level, String format, params object[] args ){
    write( level, String.Format( format, args ) );
  }
  
  public static void D( String format, params object[] args ){
    printf( Level.DBG, format, args );
  }
  
  public static void I( String format, params object[] args ){
    printf( Level.INF, format, args );
  }
  
  public static void W( String format, params object[] args ){
    printf( Level.WRN, format, args );
  }
  
  public static void E( String format, params object[] args ){
    printf( Level.ERR, format, args );
  }
  
  private static void on_log( Level level, String msg ){}
  
  static Log(){
    callback( on_log );
  }
}
}
