Skip to content

Commit

Permalink
Better logger, improve atom feed code
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Sep 8, 2017
1 parent 1b8f707 commit 0f378e5
Show file tree
Hide file tree
Showing 8 changed files with 1,013 additions and 1,007 deletions.
56 changes: 56 additions & 0 deletions Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;

public class L
{
static string filename = "log_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
static System.IO.TextWriter wr;
static bool wr_locked = false;

public static void Log(string s, bool error = false)
{
byte[] s_raw = System.Text.Encoding.ASCII.GetBytes(s);

System.Text.StringBuilder sb = new System.Text.StringBuilder(s_raw.Length);

sb.Append(DateTime.Now.ToString("T"));
sb.Append(' ');
if (error)
sb.Append("ERROR: ");

for (int i = 0; i < s.Length; i++) {
byte cur = s_raw[i];
if (cur < 32 && cur != 9) {
sb.Append('{');
sb.Append(cur);
sb.Append('}');
} else {
sb.Append((char)cur);
}
}

Console.WriteLine(sb.ToString());
}

public static void Dump(string function, string trace, string content)
{
if (wr == null)
wr = new System.IO.StreamWriter(filename, true, MAIN.E.enc);

while (wr_locked)
System.Threading.Thread.Sleep(10);

wr_locked = true;

string time = DateTime.Now.ToString("T");
wr.WriteLine("[" + time + "] Starting dump of: " + function);
if (trace != null && trace != "")
wr.WriteLine("### Trace: " + trace);
wr.WriteLine(content);
wr.WriteLine("### Dump end (" + content.Length + " characters)");
wr.Flush();

wr_locked = false;
Log(function + " failed", true);
}
}

Binary file modified Lua.cs
Binary file not shown.
1 change: 1 addition & 0 deletions NyisBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScriptEngine.cs" />
<Compile Include="Logger.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Loading

0 comments on commit 0f378e5

Please sign in to comment.