Esempio n. 1
0
        private void Log(LogSettings settings)
        {
            // Only log if the log level is appropriate
            var level = LogPluginConstants.LevelFor(LogLevel);

            // Validate: log.debug but level is Warn
            if (level < settings.LogLevelValue)
            {
                return;
            }

            // Good to log.
            string message = LogHelper.BuildMessage(ParamList);

            if (settings.OutputMode == LogPluginConstants.Console)
            {
                Console.WriteLine(LogLevel + " : " + message);
            }
            else if (settings.OutputMode == LogPluginConstants.Callback)
            {
                settings.Callback(level, message, null);
            }
            else if (settings.OutputMode == LogPluginConstants.File && settings.Logger != null)
            {
                settings.Logger.WriteLine(LogLevel + " : " + message);
            }
        }
Esempio n. 2
0
        private void Configure(LogSettings settings)
        {
            ExceptionHelper.NotNullType(this, this.ParamList[0], "log level not supplied", LTypes.String);
            ExceptionHelper.NotNullType(this, this.ParamList[1], "console or log not supplied", LTypes.String);

            // Param 1: Error level
            settings.LogLevelName  = ((LString)this.ParamList[0]).Value;
            settings.LogLevelValue = LogPluginConstants.LevelFor(settings.LogLevelName);

            // Param 2: Console or file?
            var output = ((LString)this.ParamList[1]).Value;

            if (string.Compare(output, "console", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                settings.OutputMode = LogPluginConstants.Console;
            }
            else if (string.Compare(output, "callback", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                settings.OutputMode = LogPluginConstants.Callback;
                settings.Callback   = Callback;
            }
            else
            {
                // Close any existing log
                Dispose(settings);
                SetupFileLog(settings);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Parses the day expression.
        /// Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            LogExpr logexpr = null;

            // CASE 1: logging using OO mode e.g. log.warn ( 'some message' )
            if (_tokenIt.NextToken.Token.Text == "log")
            {
                _tokenIt.Advance();

                // Move past the "." and check the log level in the next if stmt.
                if (_tokenIt.NextToken.Token == Tokens.Dot)
                {
                    _tokenIt.Advance();
                }
            }
            // CASE 2: logging using function mode e.g warn( 'some message' )
            if (LogPluginConstants.ContainsKey(_tokenIt.NextToken.Token.Text))
            {
                logexpr = new LogExpr()
                {
                    Mode = "log", LogLevel = _tokenIt.NextToken.Token.Text
                };
            }
            // CASE 3: Asking for log level
            else if (_tokenIt.NextToken.Token.Text == "level")
            {
                logexpr = new LogExpr()
                {
                    Mode = "level"
                };
            }
            // CASE 4: configuring the logger via parameters.
            else if (_tokenIt.NextToken.Token.Text == "configure")
            {
                logexpr = new LogExpr()
                {
                    Mode = "configure"
                };
            }
            else
            {
                throw _tokenIt.BuildSyntaxUnexpectedTokenException();
            }

            logexpr.Callback = _callback;

            // Move to parameters.
            _tokenIt.Advance();
            bool expectParenthesis = _tokenIt.NextToken.Token == Tokens.LeftParenthesis;

            _parser.ParseParameters(logexpr, expectParenthesis, true, true);
            return(logexpr);
        }
Esempio n. 4
0
        /// <summary>
        /// Checks whether or not this plugin can handle the current token.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        public override bool CanHandle(Token current)
        {
            if (!(current.Kind == TokenKind.Ident))
            {
                return(false);
            }

            if (current.Text == "log" || LogPluginConstants.ContainsKey(current.Text))
            {
                return(true);
            }

            return(false);
        }