コード例 #1
0
        /// <summary>
        /// Initialize
        /// </summary>
        /// <remarks>
        /// The current implementation just set to True DisplayDebug and DisplayDiagnostics
        /// </remarks>
        protected override void Initialize(LogSettings logSettings)
        {
            base.Initialize(logSettings);

            DisplayDiagnostics = true;
            DisplayDebug = true;
        }
コード例 #2
0
        /// <summary>
        /// Initialize
        /// </summary>
        /// <remarks>
        /// The current implementation just set to True DisplayConsole and DisplayDebug
        /// </remarks>
        protected override void Initialize(LogSettings logSettings)
        {
            base.Initialize(LogSettings);

            DisplayConsole = true;
            DisplayDebug = true;
        }
コード例 #3
0
        protected override void Initialize(LogSettings logSettings)
        {
            base.Initialize(logSettings);

            DisplayDebug = ((MyLogSettings)logSettings).DisplayDebugs;
            DisplayDiagnostics = ((MyLogSettings)logSettings).DisplayDiagnostics;
        }
コード例 #4
0
ファイル: LogPlugin.cs プロジェクト: GHLabs/SambaPOS-3
        private void SetupFileLog(LogSettings settings)
        {
            settings.OutputMode = LogPluginConstants.File;

            // 1st param
            var filename = ((LString)ParamList[1]).Value;
            var file = new FileInfo(filename);
            var name = file.Name.Replace(file.Extension, string.Empty);

            if (ParamList.Count > 2)
            {
                string format = Convert.ToString(ParamList[2]);
                format = format.Replace("${yyyy-MM-dd}", DateTime.Now.ToString("yyyy-MM-dd"));
                format = format.Replace("${HH-mm-ss}", DateTime.Now.ToString("HH-mm-ss"));
                format = format.Replace("${yyyy}", DateTime.Now.ToString("yyyy"));
                format = format.Replace("${yy}", DateTime.Now.ToString("yy"));
                format = format.Replace("${MM}", DateTime.Now.ToString("MM"));
                format = format.Replace("${dd}", DateTime.Now.ToString("dd"));
                format = format.Replace("${HH}", DateTime.Now.ToString("HH"));
                format = format.Replace("${mm}", DateTime.Now.ToString("mm"));
                format = format.Replace("${ss}", DateTime.Now.ToString("ss"));
                name = name + "-" + format + file.Extension;
            }
            settings.FileName = file.Directory.FullName + Path.DirectorySeparatorChar + name;

            try
            {
                settings.Logger = new StreamWriter(settings.FileName);
                settings.Logger.WriteLine("Starting log at : " + DateTime.Now.ToString("yyyy-MM-dd at HH-mm-ss"));
                settings.Logger.Flush();
            }
            catch (Exception)
            {
                throw BuildRunTimeException("Unable to log to file : " + settings.FileName);
            }
        }
コード例 #5
0
ファイル: LogPlugin.cs プロジェクト: GHLabs/SambaPOS-3
        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);            
        }
コード例 #6
0
ファイル: LogPlugin.cs プロジェクト: GHLabs/SambaPOS-3
        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);
            }
        }
コード例 #7
0
ファイル: LogPlugin.cs プロジェクト: GHLabs/SambaPOS-3
        /// <summary>
        /// Creates new instance of the type.
        /// </summary>
        /// <returns></returns>
        public override object DoEvaluate(IAstVisitor visitor)
        {
            var settings = Ctx.Plugins.GetSettings<LogSettings>("comlib.log");
            if (settings == null)
            {
                settings = new LogSettings();
                Ctx.Plugins.SetSettings("comlib.log", settings);
            }

            // 1. Resolve the parameters.
            ParamHelper.ResolveNonNamedParameters(ParamListExpressions, ParamList, visitor);
            
            if (Mode == "log")
            {
                Log(settings);
                return LObjects.EmptyString;
            }
            else if (Mode == "level")
            {
                return new LString(settings.LogLevelName);
            }
            else if (Mode == "level_check")
            {
                var level = this.LogLevel;
                if (level == "debug") return settings.LogLevelValue == LogPluginConstants.Debug;
                if (level == "info") return settings.LogLevelValue == LogPluginConstants.Info;
                if (level == "warn") return settings.LogLevelValue == LogPluginConstants.Warn;
                if (level == "error") return settings.LogLevelValue == LogPluginConstants.Error;
                if (level == "fatal") return settings.LogLevelValue == LogPluginConstants.Fatal;
                return false;
            }
            else if (Mode == "configure")
            {
                Configure(settings);
                return LObjects.EmptyString;
            }
            return LObjects.EmptyString;
        }
コード例 #8
0
 /// <summary>
 /// Constructor with a setting parameter
 /// </summary>
 /// <param name="logSettings">Custom settings or null</param>
 public TraceLogAdapter(LogSettings logSettings)
     : base(logSettings)
 {
 }
コード例 #9
0
 /// <summary>
 /// Constructor with a setting parameter
 /// </summary>
 /// <param name="logSettings">Custom settings or null</param>
 public ConsoleLogAdapter(LogSettings logSettings)
     : base(logSettings)
 {
 }
コード例 #10
0
 /// <summary>
 /// Constructor with a setting parameter
 /// </summary>
 /// <param name="logSettings">Custom settings or null</param>
 public DefaultLogAdapter(LogSettings logSettings)
 {
     LogSettings = logSettings;
     Initialize(logSettings);
 }
コード例 #11
0
 /// <summary>
 /// Initialize
 /// </summary>
 /// <remarks>
 /// The current implementation just set to True DisplayDebug
 /// </remarks>
 protected virtual void Initialize(LogSettings logSettings)
 {
     DisplayDebug = true;
 }
コード例 #12
0
 public MyLogAdapter(LogSettings logSettings)
     : base(logSettings)
 {
 }