118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Net.Mail;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using bts.log;
|
|
using mbts.config;
|
|
|
|
namespace bts.log {
|
|
internal enum Level {
|
|
Info,
|
|
Error,
|
|
Warn,
|
|
Diag,
|
|
Fatal
|
|
}
|
|
|
|
internal enum Subsystem {
|
|
gen,
|
|
Config,
|
|
QBus,
|
|
Log,
|
|
Jetfix,
|
|
MarketData,
|
|
Api,
|
|
Persistence,
|
|
User,
|
|
OrderMan,
|
|
Latency,
|
|
Assert,
|
|
Engine,
|
|
Ui,
|
|
Persist,
|
|
// Please keep this list in sync with logging.h/logging.cpp
|
|
}
|
|
}
|
|
|
|
namespace mbts
|
|
{
|
|
internal static class Logger
|
|
{
|
|
static Logger() {
|
|
}
|
|
|
|
[Conditional("DEBUG")]
|
|
// Sometimes when debugging you just want a quick, temporary, log message - use this. Don't forget to remove it.
|
|
public static void log(string message, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) {
|
|
log(Level.Info, Subsystem.gen, message, file, line);
|
|
}
|
|
|
|
public static void log(Level level, Subsystem system, string message, [CallerFilePath] string file = "c#", [CallerLineNumber] int line = 0)
|
|
{
|
|
Logger_log(level, system, message, file, line);
|
|
}
|
|
|
|
public static void error(Subsystem system, string message, [CallerFilePath] string file = "C#", [CallerLineNumber] int line = 0) {
|
|
log(Level.Error, system, message, file, line);
|
|
}
|
|
public static void warn(Subsystem system, string message, [CallerFilePath] string file = "C#", [CallerLineNumber] int line = 0) {
|
|
log(Level.Warn, system, message, file, line);
|
|
}
|
|
public static void info(Subsystem system, string message, [CallerFilePath] string file = "C#", [CallerLineNumber] int line = 0) {
|
|
log(Level.Info, system, message, file, line);
|
|
}
|
|
public static void diag(Subsystem system, string message, [CallerFilePath] string file = "C#", [CallerLineNumber] int line = 0) {
|
|
log(Level.Diag, system, message, file, line);
|
|
}
|
|
|
|
[Conditional("DEBUG")]
|
|
public static void assert_d(bool test, string message = "", [CallerFilePath] string file = "assert", [CallerLineNumber] int line = 0) {
|
|
assert(test, message, file, line);
|
|
}
|
|
|
|
public static void assert(bool test, string message = "", [CallerFilePath] string file = "assert", [CallerLineNumber] int line = 0) {
|
|
if (!test) {
|
|
log(Level.Fatal, Subsystem.Assert, message, file, line);
|
|
Debug.Assert(test, message);
|
|
if (Debugger.IsAttached) {
|
|
Debugger.Break();
|
|
}
|
|
system_is_crashing($"Fatal Assert: {message} at {file}:{line}", new StackTrace());
|
|
Environment.Exit(-1);
|
|
}
|
|
}
|
|
|
|
public static void notnull(object o) {
|
|
assert(o != null);
|
|
}
|
|
|
|
[DllImport("spark_lib")]
|
|
private static extern void Logger_log (Level level, Subsystem subsystem, string message, string file, int line);
|
|
|
|
delegate void on_crash_callback([MarshalAs(UnmanagedType.LPStr)]string msg, [MarshalAs(UnmanagedType.LPStr)] string details);
|
|
public static void system_is_crashing(string message, object details) {
|
|
OnSystemCrashing?.Invoke(message, details);
|
|
}
|
|
public static event Action<string, object> OnSystemCrashing;
|
|
}
|
|
|
|
internal interface IScreenCapture
|
|
{
|
|
Stream capture_encoded(string format);
|
|
Stream capture_encoded(string format, int width, int height);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|