public static void SetupLogging(Eyes eyes, [CallerMemberName] string testName = null) { ILogHandler logHandler; if (Environment.GetEnvironmentVariable("CI") == null) { string path = InitLogPath(testName); eyes.DebugScreenshotProvider = new FileDebugScreenshotProvider() { Path = path, Prefix = testName + "_" }; logHandler = new FileLogHandler(Path.Combine(path, $"{testName}.log"), true, true); } else { logHandler = new StdoutLogHandler(true); //logHandler_ = new TraceLogHandler(true); } if (logHandler != null) { eyes.SetLogHandler(logHandler); } }
public static void SetupLogging(Eyes eyes, [CallerMemberName] string testName = null) { ILogHandler logHandler; if (!RUNS_ON_CI) { string path = InitLogPath(testName); eyes.DebugScreenshotProvider = new FileDebugScreenshotProvider() { Path = path, Prefix = testName + "_" }; logHandler = new FileLogHandler(Path.Combine(path, testName + ".log"), true, true); //if (eyes.runner_ is VisualGridRunner visualGridRunner) //{ // visualGridRunner.DebugResourceWriter = new FileDebugResourceWriter(path); // ((VisualGridEyes)eyes.activeEyes_).debugResourceWriter_ = visualGridRunner.DebugResourceWriter; //} } else { logHandler = new NunitLogHandler(false); } if (logHandler != null) { eyes.SetLogHandler(logHandler); } Eyes.moveWindow_ = !Debugger.IsAttached; }
public static void SetupLogging(EyesRunner runner, [CallerMemberName] string testName = null, string path = null) { ILogHandler logHandler; if (!RUNS_ON_CI) { path = path ?? InitLogPath(testName); logHandler = new FileLogHandler(Path.Combine(path, testName + ".log"), true, true); //if (eyes.runner_ is VisualGridRunner visualGridRunner) //{ // visualGridRunner.DebugResourceWriter = new FileDebugResourceWriter(path); // ((VisualGridEyes)eyes.activeEyes_).debugResourceWriter_ = visualGridRunner.DebugResourceWriter; //} } else { logHandler = new NunitLogHandler(false); } if (logHandler != null) { runner.SetLogHandler(logHandler); logHandler.Open(); } }
LoggerManager() { // Initialize Loggers ConsoleLogHandler cHandler = new ConsoleLogHandler(); FileLogHandler fHandler = new FileLogHandler(Mowbly.LogFile); DatabaseLogHandler dHandler = new DatabaseLogHandler( Mowbly.GetProperty <string>(Constants.PROPERTY_LOGS_DB), float.Parse(Mowbly.GetProperty <string>(Constants.PROPERTY_LOGS_DB_VERSION)), Mowbly.LogDatabaseFile, System.String.Empty); // System Logger Logger systemLogger = GetLogger(TYPE_SYSTEM_LOGGER); systemLogger.AddHandler(fHandler); systemLogger.AddHandler(dHandler); // User Logger Logger userLogger = GetLogger(TYPE_USER_LOGGER); userLogger.AddHandler(fHandler); userLogger.AddHandler(dHandler); #if DEBUG systemLogger.AddHandler(cHandler); userLogger.AddHandler(cHandler); #endif }
public MultiLogHandler(LogLevel consoleLevel, UnityDebugLogHandler consoleHandler, LogLevel fileLevel, FileLogHandler fileHandler) { this.consoleLevel = consoleLevel; unityHander = consoleHandler; this.fileHandler = fileHandler; this.fileLevel = fileLevel; }
private static Logger InitLogging(out string path, [CallerMemberName] string caller = null) { path = TestUtils.InitLogPath(caller); string logFilePath = Path.Combine(path, caller + ".log"); Logger logger = new Logger(); FileLogHandler logHandler = new FileLogHandler(logFilePath, false, true); logHandler.Open(); logger.SetLogHandler(logHandler); return(logger); }
private void RunVisualGridDemo() { // Create a runner with concurrency of 10 VisualGridRunner runner = new VisualGridRunner(10); // Create a file logger with default file ('eyes.log', verbose, in current directory). FileLogHandler logHandler = new FileLogHandler(); // Set the log handler. runner.SetLogHandler(logHandler); // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes. Eyes eyes = new Eyes(runner); // Create Selenium Configuration. Configuration sconf = new Configuration(); // Set app name sconf.AppName = "Visual Grid Demo App"; // Set test name sconf.TestName = "Visual Grid Demo Test"; // Add browsers sconf.AddBrowser(800, 600, Configuration.BrowserType.CHROME); sconf.AddBrowser(700, 500, Configuration.BrowserType.FIREFOX); sconf.AddBrowser(1200, 800, Configuration.BrowserType.IE10); sconf.AddBrowser(1200, 800, Configuration.BrowserType.IE11); sconf.AddBrowser(1600, 1200, Configuration.BrowserType.EDGE); // Add iPhone 4 device emulation EmulationInfo iphone4 = new EmulationInfo(EmulationInfo.DeviceNameEnum.iPhone_4, ScreenOrientation.Portrait); sconf.AddDeviceEmulation(iphone4); // Add custom mobile device emulation EmulationDevice customMobile = new EmulationDevice(width: 1024, height: 768, deviceScaleFactor: 2); sconf.AddDeviceEmulation(customMobile); sconf.AddDeviceEmulation(EmulationInfo.DeviceNameEnum.iPhone_5SE, ScreenOrientation.Landscape); sconf.AddDeviceEmulation(EmulationInfo.DeviceNameEnum.Galaxy_S5); sconf.AddDeviceEmulation(800, 640); RunTest(eyes, sconf); TestResultSummary allTestResults = runner.GetAllTestResults(); }
public void WritesMessageToFile() { const string file = "log2.txt"; File.Delete(file); var debugMessage = "*debug message*" + DateTime.UtcNow.ToStringInvariant("o"); using (var log = new FileLogHandler(file)) { log.Debug(debugMessage); } var contents = File.ReadAllText(file); Assert.IsNotNull(contents); Assert.IsTrue(contents.Contains(debugMessage)); File.Delete(file); }
private void RunSeleniumDemo() { // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes. Eyes eyes = new Eyes(); // Create a file logger with default file ('eyes.log', verbose, in current directory). FileLogHandler logHandler = new FileLogHandler(); // Set the log handler. eyes.SetLogHandler(logHandler); // Create Selenium Configuration. Configuration sconf = new Configuration(); sconf.AppName = "Selenium WebDriver Demo App"; sconf.TestName = "Selenium WebDriver Demo Test"; sconf.ViewportSize = new Size(640, 480); RunTest(eyes, sconf); }
/// <summary> /// Prova a configurare il gestore delle operazioni di logging, creando la cartella in cui verrà memorizzato /// il nuovo file di log e un nuovo file di testo in cui verrà conservato il log delle operazioni di logging /// e restituendo true se non si verificano errori durante la procedura. In caso contrario viene mostrato un /// errore esplicativo e restituisce false. /// </summary> /// <returns>true se non si verificano errori durante la configurazione del logger, altrimenti false</returns> static bool ConfigureLogger() { Settings appConfig = Settings.Instance; Logger appLogger = Logger.Instance; string logFileName = string.Format("{0:yyyyMMdd_HHmmss}.log", DateTime.Now); try { FileLogHandler handler = new FileLogHandler(Path.Combine(appConfig.LogsFolder, logFileName)); handler.LogBufferMaxSize = 10; appLogger.Add(handler); return(true); } catch (Exception e) { Console.WriteLine("Error during configuration of the logger: {0}", e.ToString()); Console.WriteLine(); return(false); } }
public void UsesGlobalFilePath() { var previous = Log.FilePath; Directory.CreateDirectory("filePathTest"); Log.FilePath = Path.Combine("filePathTest", "log2.txt"); File.Delete(Log.FilePath); var debugMessage = "*debug message*" + DateTime.UtcNow.ToStringInvariant("o"); using (var log = new FileLogHandler()) { log.Debug(debugMessage); } var contents = File.ReadAllText(Log.FilePath); File.Delete(Log.FilePath); Log.FilePath = previous; Assert.IsNotNull(contents); Assert.IsTrue(contents.Contains(debugMessage)); }
public static void SetupLogging(EyesBase eyes, [CallerMemberName] string testName = null) { ILogHandler logHandler = null; if (!RUNS_ON_CI) { string path = InitLogPath(testName); eyes.DebugScreenshotProvider = new FileDebugScreenshotProvider() { Path = path, Prefix = testName + "_" }; logHandler = new FileLogHandler(Path.Combine(path, testName + ".log"), true, true); } else { logHandler = new NunitLogHandler(false); } if (logHandler != null) { eyes.SetLogHandler(logHandler); } }
/// <inheritdoc /> public bool Start() { // Sets up the configMgr // If a config file path was passed, use it literally. // This ensures it's working-directory relative // (for people passing config file through the terminal or something). // Otherwise use the one next to the executable. if (_commandLineArgs?.ConfigFile != null) { _config.LoadFromFile(_commandLineArgs.ConfigFile); } else { var path = PathHelpers.ExecutableRelativeFile("server_config.toml"); if (File.Exists(path)) { _config.LoadFromFile(path); } else { _config.SetSaveFile(path); } } if (_commandLineArgs != null) { _config.OverrideConVars(_commandLineArgs.CVars); } //Sets up Logging _config.RegisterCVar("log.path", "logs", CVar.ARCHIVE); _config.RegisterCVar("log.format", "log_%(date)s-%(time)s.txt", CVar.ARCHIVE); _config.RegisterCVar("log.level", LogLevel.Info, CVar.ARCHIVE); var logPath = _config.GetCVar <string>("log.path"); var logFormat = _config.GetCVar <string>("log.format"); var logFilename = logFormat.Replace("%(date)s", DateTime.Now.ToString("yyyyMMdd")) .Replace("%(time)s", DateTime.Now.ToString("hhmmss")); var fullPath = Path.Combine(logPath, logFilename); if (!Path.IsPathRooted(fullPath)) { logPath = PathHelpers.ExecutableRelativeFile(fullPath); } fileLogHandler = new FileLogHandler(logPath); _log.RootSawmill.Level = _config.GetCVar <LogLevel>("log.level"); _log.RootSawmill.AddHandler(fileLogHandler); // Has to be done early because this guy's in charge of the main thread Synchronization Context. _taskManager.Initialize(); LoadSettings(); var netMan = IoCManager.Resolve <IServerNetManager>(); try { netMan.Initialize(true); netMan.StartServer(); } catch (Exception e) { var port = netMan.Port; Logger.Fatal( "Unable to setup networking manager. Check port {0} is not already in use and that all binding addresses are correct!\n{1}", port, e); return(true); } var dataDir = _commandLineArgs?.DataDir ?? PathHelpers.ExecutableRelativeFile("data"); // Set up the VFS _resources.Initialize(dataDir); #if FULL_RELEASE _resources.MountContentDirectory(@"./Resources/"); #else // Load from the resources dir in the repo root instead. // It's a debug build so this is fine. var contentRootDir = ProgramShared.FindContentRootDir(); _resources.MountContentDirectory($@"{contentRootDir}RobustToolbox/Resources/"); _resources.MountContentDirectory($@"{contentRootDir}bin/Content.Server/", new ResourcePath("/Assemblies/")); _resources.MountContentDirectory($@"{contentRootDir}Resources/"); #endif // Default to en-US. // Perhaps in the future we could make a command line arg or something to change this default. _localizationManager.LoadCulture(new CultureInfo("en-US")); //identical code in game controller for client if (!_modLoader.TryLoadAssembly <GameShared>(_resources, $"Content.Shared")) { Logger.FatalS("eng", "Could not load any Shared DLL."); return(true); } if (!_modLoader.TryLoadAssembly <GameServer>(_resources, $"Content.Server")) { Logger.FatalS("eng", "Could not load any Server DLL."); return(true); } // HAS to happen after content gets loaded. // Else the content types won't be included. // TODO: solve this properly. _serializer.Initialize(); // Initialize Tier 2 services IoCManager.Resolve <IGameTiming>().InSimulation = true; _stateManager.Initialize(); _entities.Initialize(); IoCManager.Resolve <IPlayerManager>().Initialize(MaxPlayers); _mapManager.Initialize(); _mapManager.Startup(); IoCManager.Resolve <IPlacementManager>().Initialize(); IoCManager.Resolve <IViewVariablesHost>().Initialize(); IoCManager.Resolve <IDebugDrawingManager>().Initialize(); // Call Init in game assemblies. _modLoader.BroadcastRunLevel(ModRunLevel.Init); // because of 'reasons' this has to be called after the last assembly is loaded // otherwise the prototypes will be cleared var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); prototypeManager.LoadDirectory(new ResourcePath(@"/Prototypes")); prototypeManager.Resync(); IoCManager.Resolve <IConsoleShell>().Initialize(); IoCManager.Resolve <IConGroupController>().Initialize(); _entities.Startup(); _modLoader.BroadcastRunLevel(ModRunLevel.PostInit); IoCManager.Resolve <IStatusHost>().Start(); AppDomain.CurrentDomain.ProcessExit += ProcessExiting; return(false); }
/// <inheritdoc /> public bool Start() { //Sets up the configMgr _config.LoadFromFile(_commandLine.ConfigFile); //Sets up Logging _config.RegisterCVar("log.path", "logs", CVar.ARCHIVE); _config.RegisterCVar("log.format", "log_%(date)s-%(time)s.txt", CVar.ARCHIVE); _config.RegisterCVar("log.level", LogLevel.Info, CVar.ARCHIVE); var logPath = _config.GetCVar <string>("log.path"); var logFormat = _config.GetCVar <string>("log.format"); var logFilename = logFormat.Replace("%(date)s", DateTime.Now.ToString("yyyyMMdd")).Replace("%(time)s", DateTime.Now.ToString("hhmmss")); var fullPath = Path.Combine(logPath, logFilename); if (!Path.IsPathRooted(fullPath)) { logPath = PathHelpers.ExecutableRelativeFile(fullPath); } fileLogHandler = new FileLogHandler(logPath); _log.RootSawmill.Level = _config.GetCVar <LogLevel>("log.level"); _log.RootSawmill.AddHandler(fileLogHandler); // Has to be done early because this guy's in charge of the main thread Synchronization Context. _taskManager.Initialize(); LoadSettings(); var netMan = IoCManager.Resolve <IServerNetManager>(); try { netMan.Initialize(true); netMan.StartServer(); } catch (Exception e) { var port = netMan.Port; Logger.Fatal("Unable to setup networking manager. Check port {0} is not already in use and that all binding addresses are correct!\n{1}", port, e); return(true); } // Set up the VFS _resources.Initialize(); #if RELEASE _resources.MountContentDirectory(@"./Resources/"); #else // Load from the resources dir in the repo root instead. // It's a debug build so this is fine. _resources.MountContentDirectory(@"../../Resources/"); _resources.MountContentDirectory(@"../../../bin/Content.Server/", new ResourcePath("/Assemblies/")); #endif //mount the engine content pack // _resources.MountContentPack(@"EngineContentPack.zip"); //mount the default game ContentPack defined in config // _resources.MountDefaultContentPack(); //identical code in game controller for client if (!AssemblyLoader.TryLoadAssembly <GameShared>(_resources, $"Content.Shared")) { Logger.Warning($"[ENG] Could not load any Shared DLL."); } if (!AssemblyLoader.TryLoadAssembly <GameServer>(_resources, $"Content.Server")) { Logger.Warning($"[ENG] Could not load any Server DLL."); } // HAS to happen after content gets loaded. // Else the content types won't be included. // TODO: solve this properly. _serializer.Initialize(); // Initialize Tier 2 services _stateManager.Initialize(); _entities.Initialize(); IoCManager.Resolve <IChatManager>().Initialize(); IoCManager.Resolve <IPlayerManager>().Initialize(MaxPlayers); _mapManager.Initialize(); IoCManager.Resolve <IPlacementManager>().Initialize(); IoCManager.Resolve <IViewVariablesHost>().Initialize(); // Call Init in game assemblies. AssemblyLoader.BroadcastRunLevel(AssemblyLoader.RunLevel.Init); // because of 'reasons' this has to be called after the last assembly is loaded // otherwise the prototypes will be cleared var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); prototypeManager.LoadDirectory(new ResourcePath(@"/Prototypes")); prototypeManager.Resync(); IoCManager.Resolve <ITileDefinitionManager>().Initialize(); IoCManager.Resolve <IConsoleShell>().Initialize(); IoCManager.Resolve <IConGroupController>().Initialize(); AssemblyLoader.BroadcastRunLevel(AssemblyLoader.RunLevel.PostInit); _entities.Startup(); IoCManager.Resolve <IStatusHost>().Start(); return(false); }
/// <inheritdoc /> public bool Start(Func <ILogHandler>?logHandlerFactory = null) { if (LoadConfigAndUserData) { // Sets up the configMgr // If a config file path was passed, use it literally. // This ensures it's working-directory relative // (for people passing config file through the terminal or something). // Otherwise use the one next to the executable. if (_commandLineArgs?.ConfigFile != null) { _config.LoadFromFile(_commandLineArgs.ConfigFile); } else { var path = PathHelpers.ExecutableRelativeFile("server_config.toml"); if (File.Exists(path)) { _config.LoadFromFile(path); } else { _config.SetSaveFile(path); } } } _config.OverrideConVars(EnvironmentVariables.GetEnvironmentCVars()); if (_commandLineArgs != null) { _config.OverrideConVars(_commandLineArgs.CVars); } //Sets up Logging _config.RegisterCVar("log.enabled", true, CVar.ARCHIVE); _config.RegisterCVar("log.path", "logs", CVar.ARCHIVE); _config.RegisterCVar("log.format", "log_%(date)s-T%(time)s.txt", CVar.ARCHIVE); _config.RegisterCVar("log.level", LogLevel.Info, CVar.ARCHIVE); _config.RegisterCVar("log.runtimelog", true, CVar.ARCHIVE); _logHandlerFactory = logHandlerFactory; var logHandler = logHandlerFactory?.Invoke() ?? null; var logEnabled = _config.GetCVar <bool>("log.enabled"); if (logEnabled && logHandler == null) { var logPath = _config.GetCVar <string>("log.path"); var logFormat = _config.GetCVar <string>("log.format"); var logFilename = logFormat.Replace("%(date)s", DateTime.Now.ToString("yyyy-MM-dd")) .Replace("%(time)s", DateTime.Now.ToString("hh-mm-ss")); var fullPath = Path.Combine(logPath, logFilename); if (!Path.IsPathRooted(fullPath)) { logPath = PathHelpers.ExecutableRelativeFile(fullPath); } logHandler = new FileLogHandler(logPath); } _log.RootSawmill.Level = _config.GetCVar <LogLevel>("log.level"); if (logEnabled && logHandler != null) { _logHandler = logHandler; _log.RootSawmill.AddHandler(_logHandler !); } SelfLog.Enable(s => { System.Console.WriteLine("SERILOG ERROR: {0}", s); }); if (!SetupLoki()) { return(true); } // Has to be done early because this guy's in charge of the main thread Synchronization Context. _taskManager.Initialize(); LoadSettings(); // Load metrics really early so that we can profile startup times in the future maybe. _metricsManager.Initialize(); var netMan = IoCManager.Resolve <IServerNetManager>(); try { netMan.Initialize(true); netMan.StartServer(); netMan.RegisterNetMessage <MsgSetTickRate>(MsgSetTickRate.NAME); } catch (Exception e) { var port = netMan.Port; Logger.Fatal( "Unable to setup networking manager. Check port {0} is not already in use and that all binding addresses are correct!\n{1}", port, e); return(true); } var dataDir = LoadConfigAndUserData ? _commandLineArgs?.DataDir ?? PathHelpers.ExecutableRelativeFile("data") : null; // Set up the VFS _resources.Initialize(dataDir); #if FULL_RELEASE _resources.MountContentDirectory(@"./Resources/"); #else // Load from the resources dir in the repo root instead. // It's a debug build so this is fine. var contentRootDir = ProgramShared.FindContentRootDir(); _resources.MountContentDirectory($@"{contentRootDir}RobustToolbox/Resources/"); _resources.MountContentDirectory($@"{contentRootDir}bin/Content.Server/", new ResourcePath("/Assemblies/")); _resources.MountContentDirectory($@"{contentRootDir}Resources/"); #endif _modLoader.SetUseLoadContext(!DisableLoadContext); //identical code in game controller for client if (!_modLoader.TryLoadAssembly <GameShared>(_resources, $"Content.Shared")) { Logger.FatalS("eng", "Could not load any Shared DLL."); return(true); } if (!_modLoader.TryLoadAssembly <GameServer>(_resources, $"Content.Server")) { Logger.FatalS("eng", "Could not load any Server DLL."); return(true); } _modLoader.BroadcastRunLevel(ModRunLevel.PreInit); // HAS to happen after content gets loaded. // Else the content types won't be included. // TODO: solve this properly. _serializer.Initialize(); //IoCManager.Resolve<IMapLoader>().LoadedMapData += // IoCManager.Resolve<IRobustMappedStringSerializer>().AddStrings; IoCManager.Resolve <IPrototypeManager>().LoadedData += IoCManager.Resolve <IRobustMappedStringSerializer>().AddStrings; // Initialize Tier 2 services IoCManager.Resolve <IGameTiming>().InSimulation = true; _stateManager.Initialize(); IoCManager.Resolve <IPlayerManager>().Initialize(MaxPlayers); _mapManager.Initialize(); _mapManager.Startup(); IoCManager.Resolve <IPlacementManager>().Initialize(); IoCManager.Resolve <IViewVariablesHost>().Initialize(); IoCManager.Resolve <IDebugDrawingManager>().Initialize(); // Call Init in game assemblies. _modLoader.BroadcastRunLevel(ModRunLevel.Init); _entities.Initialize(); // because of 'reasons' this has to be called after the last assembly is loaded // otherwise the prototypes will be cleared var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); prototypeManager.LoadDirectory(new ResourcePath(@"/Prototypes")); prototypeManager.Resync(); IoCManager.Resolve <IConsoleShell>().Initialize(); IoCManager.Resolve <IConGroupController>().Initialize(); _entities.Startup(); _scriptHost.Initialize(); _modLoader.BroadcastRunLevel(ModRunLevel.PostInit); IoCManager.Resolve <IStatusHost>().Start(); AppDomain.CurrentDomain.ProcessExit += ProcessExiting; _watchdogApi.Initialize(); return(false); }