Exemplo n.º 1
0
        /*********
        ** Public methods
        *********/
        /****
        ** Initialization
        ****/
        /// <summary>Construct an instance.</summary>
        /// <param name="logPath">The log file path to write.</param>
        /// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
        /// <param name="writeToConsole">Whether to output log messages to the console.</param>
        /// <param name="isVerbose">Whether verbose logging is enabled. This enables more detailed diagnostic messages than are normally needed.</param>
        /// <param name="isDeveloperMode">Whether to enable full console output for developers.</param>
        /// <param name="getScreenIdForLog">Get the screen ID that should be logged to distinguish between players in split-screen mode, if any.</param>
        public LogManager(string logPath, ColorSchemeConfig colorConfig, bool writeToConsole, bool isVerbose, bool isDeveloperMode, Func <int?> getScreenIdForLog)
        {
            // init construction logic
            this.GetMonitorImpl = name => new Monitor(name, this.IgnoreChar, this.LogFile, colorConfig, isVerbose, getScreenIdForLog)
            {
                WriteToConsole         = writeToConsole,
                ShowTraceInConsole     = isDeveloperMode,
                ShowFullStampInConsole = isDeveloperMode
            };

            // init fields
            this.LogFile        = new LogFileManager(logPath);
            this.Monitor        = this.GetMonitor("SMAPI");
            this.MonitorForGame = this.GetMonitor("game");

            // redirect direct console output
            var output = new InterceptingTextWriter(Console.Out, this.IgnoreChar);

            if (writeToConsole)
            {
                output.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message);
            }
            Console.SetOut(output);

            // enable Unicode handling on Windows
            // (the terminal defaults to UTF-8 on Linux/macOS)
#if SMAPI_FOR_WINDOWS
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;
#endif
        }
Exemplo n.º 2
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="source">The name of the module which logs messages using this instance.</param>
        /// <param name="ignoreChar">A character which indicates the message should not be intercepted if it appears as the first character of a string written to the console. The character itself is not logged in that case.</param>
        /// <param name="logFile">The log file to which to write messages.</param>
        /// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
        /// <param name="isVerbose">Whether verbose logging is enabled. This enables more detailed diagnostic messages than are normally needed.</param>
        public Monitor(string source, char ignoreChar, LogFileManager logFile, ColorSchemeConfig colorConfig, bool isVerbose)
        {
            // validate
            if (string.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentException("The log source cannot be empty.");
            }

            // initialize
            this.Source        = source;
            this.LogFile       = logFile ?? throw new ArgumentNullException(nameof(logFile), "The log file manager cannot be null.");
            this.ConsoleWriter = new ColorfulConsoleWriter(Constants.Platform, colorConfig);
            this.IgnoreChar    = ignoreChar;
            this.IsVerbose     = isVerbose;
        }
Exemplo n.º 3
0
        /*********
        ** Public methods
        *********/
        /****
        ** Initialization
        ****/
        /// <summary>Construct an instance.</summary>
        /// <param name="logPath">The log file path to write.</param>
        /// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
        /// <param name="writeToConsole">Whether to output log messages to the console.</param>
        /// <param name="isVerbose">Whether verbose logging is enabled. This enables more detailed diagnostic messages than are normally needed.</param>
        /// <param name="isDeveloperMode">Whether to enable full console output for developers.</param>
        public LogManager(string logPath, ColorSchemeConfig colorConfig, bool writeToConsole, bool isVerbose, bool isDeveloperMode)
        {
            // init construction logic
            this.GetMonitorImpl = name => new Monitor(name, this.IgnoreChar, this.LogFile, colorConfig, isVerbose)
            {
                WriteToConsole         = writeToConsole,
                ShowTraceInConsole     = isDeveloperMode,
                ShowFullStampInConsole = isDeveloperMode
            };

            // init fields
            this.LogFile        = new LogFileManager(logPath);
            this.Monitor        = this.GetMonitor("SMAPI");
            this.MonitorForGame = this.GetMonitor("game");

            // redirect direct console output
            var output = new InterceptingTextWriter(Console.Out, this.IgnoreChar);

            if (writeToConsole)
            {
                output.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message);
            }
            Console.SetOut(output);
        }