Advertisement
mkv

logger

mkv
Feb 20th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1.     public class Logger
  2.     {
  3.         public static Logger mp3, ogg, pcm, med, mix, tag, app;
  4.         public static List<double> bitratem, bitrateo;
  5.         public static void init()
  6.         {
  7.             bitratem = new List<double>();
  8.             bitrateo = new List<double>();
  9.             pcm = new Logger();
  10.             med = new Logger();
  11.             mix = new Logger();
  12.             mp3 = new Logger();
  13.             ogg = new Logger();
  14.             tag = new Logger();
  15.             app = new Logger();
  16.         }
  17.         public long i, msg;
  18.        
  19.         Entry[] buf;
  20.         public class Entry
  21.         {
  22.             public long tick;
  23.             public long num;
  24.             public string msg;
  25.             public Entry()
  26.             {
  27.                 tick = num = -1;
  28.                 msg = "";
  29.             }
  30.         }
  31.        
  32.         public Logger()
  33.         {
  34.             i = msg = 0;
  35.             buf = new Entry[1024];
  36.             for (int a = 0; a < buf.Length; a++)
  37.             {
  38.                 buf[a] = new Entry();
  39.             }
  40.         }
  41.         public override string ToString()
  42.         {
  43.             Entry e;
  44.             lock (buf)
  45.             {
  46.                 e = buf[i];
  47.             }
  48.             if (e.tick <= 0) return "not active";
  49.             return new DateTime(e.tick, DateTimeKind.Utc)
  50.                 .ToString("yyyy-MM-dd HH:mm:ss.ffff") +
  51.                 " " + e.num.ToString().PadLeft(7) +
  52.                 " | " + e.msg;
  53.         }
  54.         public void a(string text)
  55.         {
  56.             lock (buf)
  57.             {
  58.                 if (text == buf[i].msg)
  59.                 {
  60.                     buf[i].num = ++msg;
  61.                     return;
  62.                 }
  63.                 if (++i >= buf.Length) i = 0;
  64.                 Entry e = buf[i];
  65.                 e.msg = text;
  66.                 e.num = ++msg;
  67.                 e.tick = DateTime.UtcNow.Ticks;
  68.             }
  69.         }
  70.         public string compile()
  71.         {
  72.             StringBuilder ret = new StringBuilder();
  73.             lock (buf)
  74.             {
  75.                 long o = i;
  76.                 while (true)
  77.                 {
  78.                     if (buf[i].num >= 0)
  79.                     {
  80.                         ret.AppendLine(ToString());
  81.                     }
  82.                     if (--i < 0) i = buf.Length - 1;
  83.                     if (i == o) break;
  84.                 }
  85.             }
  86.             return ret.ToString();
  87.         }
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement