Add experimental debug logging
This commit is contained in:
parent
fc99995415
commit
48338805bd
6 changed files with 101 additions and 10 deletions
|
@ -6,7 +6,7 @@ using System.Reflection;
|
|||
[assembly: AssemblyCompany("ZNI")]
|
||||
[assembly: AssemblyAlgorithmId(System.Configuration.Assemblies.AssemblyHashAlgorithm.MD5)]
|
||||
[assembly: AssemblyCopyright("© 2020 Tara Piccari")]
|
||||
[assembly: AssemblyFileVersion("5.2.018")]
|
||||
[assembly: AssemblyFileVersion("5.2.109")]
|
||||
[assembly: AssemblyDescription("Second Life Bot - BotCore5")]
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace Bot.Assemble
|
|||
public class ASMInfo
|
||||
{
|
||||
public static string BotName = "ZBotCore";
|
||||
public static string BotVer = "5.2.018";
|
||||
public static string BotVer = "5.2.109";
|
||||
public static string GitPassword
|
||||
{
|
||||
get
|
||||
|
|
58
ChatLogger.cs
Normal file
58
ChatLogger.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using Bot.CommandSystem;
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bot
|
||||
{
|
||||
public sealed class ChatLogger
|
||||
{
|
||||
private static readonly object writelock = new object();
|
||||
private static ChatLogger inst = null;
|
||||
static ChatLogger() { }
|
||||
public static ChatLogger Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (inst != null) return inst;
|
||||
else
|
||||
{
|
||||
if (inst == null)
|
||||
{
|
||||
inst = new ChatLogger();
|
||||
}
|
||||
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Debug function to log chat and IMs incase of errors.
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="level"></param>
|
||||
/// <param name="grid"></param>
|
||||
/// <param name="additionalArgs"></param>
|
||||
/// <param name="MHE"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="registry"></param>
|
||||
/// <param name="agentKey"></param>
|
||||
/// <param name="agentName"></param>
|
||||
[CommandGroup("log_chat", 5, 0, "log_chat - Toggles chat and IM logging", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_CONSOLE_INFO)]
|
||||
public void toggleChatLog(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName)
|
||||
{
|
||||
MHE(source, client, "Toggling");
|
||||
|
||||
MainConfiguration.Instance.LogChatAndIMs = !MainConfiguration.Instance.LogChatAndIMs;
|
||||
MainConfiguration.Instance.Save();
|
||||
|
||||
MHE(source, client, "Logging is now set to: " + MainConfiguration.Instance.LogChatAndIMs.ToString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -69,6 +69,15 @@ namespace Bot.CommandSystem
|
|||
else sourceLoc = MessageHandler.Destinations.DEST_LOCAL;
|
||||
|
||||
string agentName = parameters.fromName;
|
||||
if(sourceLoc == MessageHandler.Destinations.DEST_LOCAL)
|
||||
{
|
||||
GroupLog.Instance.WriteLogEntry(true, false, agentName, agentKey, request);
|
||||
}else if (sourceLoc == MessageHandler.Destinations.DEST_AGENT)
|
||||
{
|
||||
GroupLog.Instance.WriteLogEntry(false, true, agentName, agentKey, request);
|
||||
}
|
||||
|
||||
|
||||
if (sourceLoc == MessageHandler.Destinations.DEST_GROUP)
|
||||
{
|
||||
agentKey = fromID;
|
||||
|
|
|
@ -65,6 +65,9 @@ namespace Bot
|
|||
public string SSLCertificatePFX { get; set; } = "certificate.pfx";
|
||||
public string SSLCertificatePWD { get; set; } = "";
|
||||
|
||||
public bool LogChatAndIMs { get; set; } = false;
|
||||
public string IMAndChatFormat { get; set; } = "[%TIME%] (%NAME%): %MESSAGE%";
|
||||
|
||||
public Dictionary<UUID, int> BotAdmins { get; set; } = new Dictionary<UUID, int>();
|
||||
|
||||
public List<string> AuthedGithubUsers { get; set; } = new List<string>();
|
||||
|
|
27
GroupLog.cs
27
GroupLog.cs
|
@ -51,6 +51,33 @@ namespace Bot
|
|||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
public void WriteLogEntry(bool isLocal, bool isIM, string SenderName, UUID SenderID, string Message)
|
||||
{
|
||||
string filename = "";
|
||||
if (isLocal) filename = DateTime.Now.ToString("M-d-yyyy")+"-LocalChat.log";
|
||||
else filename = DateTime.Now.ToString("M-d-yyyy") + "-"+SenderName + ".log";
|
||||
|
||||
string LogFormat = MainConfiguration.Instance.IMAndChatFormat;
|
||||
LogFormat=LogFormat.Replace("%TIME%", DateTime.Now.ToString("hh:mm:ss"));
|
||||
LogFormat = LogFormat.Replace("%NAME%", SenderName);
|
||||
LogFormat = LogFormat.Replace("%MESSAGE%", Message);
|
||||
LogFormat = LogFormat.Replace("%UUID%", SenderID.ToString());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
lock (_writeLock)
|
||||
{
|
||||
if (!Directory.Exists("GroupChatLogs")) Directory.CreateDirectory("GroupChatLogs");
|
||||
File.AppendAllText(filename, LogFormat + "\n");
|
||||
}
|
||||
}catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Could not write a log using overload1 (chat or IM)\nError code: " + e.Message + "\nStack: " + e.StackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static readonly object _fileRead = new object();
|
||||
[CommandGroupMaster("Logging")]
|
||||
[CommandGroup("search_log", 5, 2, "search_log [groupName] [search_term] - Searches for the search term in all logs relating to the group name (Use a underscore to show where spaces are!). The search term may also include the pipe (|) delimiter to include more than 1 word.", Bot.MessageHandler.Destinations.DEST_AGENT | Bot.MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP | MessageHandler.Destinations.DEST_DISCORD)]
|
||||
|
|
10
Program.cs
10
Program.cs
|
@ -47,6 +47,7 @@ namespace Bot
|
|||
|
||||
public static unsafe void Main(string[] args)
|
||||
{
|
||||
Console.SetOut(new StreamWriter(new FileStream("Console.log", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)));
|
||||
Console.WriteLine("Setting up Main Configuration");
|
||||
Log = new Logger("BotCore5");
|
||||
BotSession.Instance.Logger = Log;
|
||||
|
@ -57,7 +58,6 @@ namespace Bot
|
|||
MainConfiguration.Instance.Load();
|
||||
MainConfiguration conf = MainConfiguration.Instance;
|
||||
//MasterObjectCaches = ObjectCaches.Instance;
|
||||
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
|
||||
|
||||
if (args.Length == 2)
|
||||
{
|
||||
|
@ -493,12 +493,6 @@ namespace Bot
|
|||
//System.Console.ReadKey();
|
||||
}
|
||||
|
||||
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
|
||||
{
|
||||
// Exit the process
|
||||
if (File.Exists("Bot.lockfile")) File.Delete("Bot.lockfile");
|
||||
}
|
||||
|
||||
private static void onJoinGroupChat(object sender, GroupChatJoinedEventArgs e)
|
||||
{
|
||||
if (e.Success)
|
||||
|
@ -817,7 +811,7 @@ namespace Bot
|
|||
newCache.GroupID = e.GroupID;
|
||||
newCache.Save(e.GroupID.ToString());
|
||||
RoleReply.Set();
|
||||
FileInfo fi = new FileInfo("GroupCache/" + e.GroupID.ToString() + ".bdf");
|
||||
FileInfo fi = new FileInfo("GroupCache/" + e.GroupID.ToString() + ".json");
|
||||
|
||||
//MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "[debug] Roles for secondlife:///app/group/" + e.GroupID.ToString() + "/about have been saved to: GroupCache/" + e.GroupID.ToString() + ".bdf\nFileSize: "+fi.Length.ToString(), 55);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue