static public BMyLog4PB getLogger(BaconArgs ArgBag, Program Assembly) { byte filter = getVerbosityFilter(ArgBag); if (filter == 0) { return(null); } string tag = ArgBag.hasOption(BMyArgParams.LOG_TAG) ? ArgBag.getOption(BMyArgParams.LOG_TAG)[0] : BMyArgParams.LOG_TAG_DEFAULT; BMyLog4PB Logger = new BMyLog4PB( Assembly, filter, new BMyLog4PB.BMyEchoAppender(Assembly), new BMyLog4PB.BMyKryptDebugSrvAppender(Assembly), new BMyLog4PB.BMyTextPanelAppender( tag, Assembly ) ); if (ArgBag.hasOption(BMyArgParams.LOG_FORMAT)) { Logger.Format = ArgBag.getOption(BMyArgParams.LOG_FORMAT)[0]; } Logger.AutoFlush = false; Logger.If(BMyLog4PB.E_DEBUG)?.Debug("Log initialized. Tag: {0}, Format: {1}", tag, Logger.Format); return(Logger); }
public void Main(string argument) { // The main entry point of the script, invoked every time // one of the programmable block's Run actions are invoked. // // The method itself is required, but the argument above // can be removed if not needed. BMyLog4PB Log = new BMyLog4PB(this, BMyLog4PB.E_ALL, new BMyLog4PB.BMyTextPanelAppender("DrawLog", this)); Log.AutoFlush = true; IMyTextPanel panel = GridTerminalSystem.GetBlockWithName("DrawPanel") as IMyTextPanel; if (panel == null) { throw new Exception("Panel \"DrawPanel\" not found"); } string[] code = panel?.CustomData.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); Log?.PushStack("BaconDraw"); string image = (new BaconDraw()).run(code, Log).ToString(); Log.PopStack(); panel?.WritePublicText(image); panel?.ShowPublicTextOnScreen(); }
public BMyEnvironment(Program Assembly) { this.Assembly = Assembly; Log = new BMyLog4PB(Assembly, BMyLog4PB.E_ALL, new BMyLog4PB.BMyCustomDataAppender(Assembly)); DrawPlugins = new BMyPluginBag <BMyDrawPlugin>(this); Log.Debug("Environment initialized."); }
public Environment(Program App, string argument, UpdateType updateSource) { this.App = App; this.argumentRaw = argument; this.GlobalArgs = BaconArgs.parse(argument); this.updateSource = updateSource; this.Log = NewLog(); }
private BMyLog4PB NewLog() { if (App == null || GlobalArgs == null) { return(null); } BMyLog4PB TempLogger; string verbosity = GlobalArgs.getOption("LogLevel")[0]?.Trim() ?? "error"; if (verbosity.Equals("OFF")) { TempLogger = null; } else { TempLogger = new BMyLog4PB(this.App); switch (verbosity) { case "trace": TempLogger.Filter = BMyLog4PB.E_TRACE | BMyLog4PB.E_DEBUG | BMyLog4PB.E_INFO | BMyLog4PB.E_WARN | BMyLog4PB.E_ERROR | BMyLog4PB.E_FATAL; break; case "debug": TempLogger.Filter = BMyLog4PB.E_DEBUG | BMyLog4PB.E_INFO | BMyLog4PB.E_WARN | BMyLog4PB.E_ERROR | BMyLog4PB.E_FATAL; break; case "info": TempLogger.Filter = BMyLog4PB.E_INFO | BMyLog4PB.E_WARN | BMyLog4PB.E_ERROR | BMyLog4PB.E_FATAL; break; case "warn": TempLogger.Filter = BMyLog4PB.E_WARN | BMyLog4PB.E_ERROR | BMyLog4PB.E_FATAL; break; case "error": TempLogger.Filter = BMyLog4PB.E_ERROR | BMyLog4PB.E_FATAL; break; case "fatal": TempLogger.Filter = BMyLog4PB.E_FATAL; break; default: TempLogger.Filter = BMyLog4PB.E_ERROR | BMyLog4PB.E_FATAL; break; } foreach (KeyValuePair <string, string> logMsg in LogMessages) { TempLogger.SetMessage(logMsg.Key, logMsg.Value); } TempLogger.AutoFlush = true; TempLogger.AddAppender(new BMyLog4PB.BMyTextPanelAppender(GlobalArgs.getOption("LogLCD")[0]?.Trim() ?? "[BCC-LOG]", App)); TempLogger.Info("L1"); } return(TempLogger); }
public Canvas run(string[] source, BMyLog4PB Log) { Log?.PushStack(@"BaconDraw.run"); Log?.IfDebug?.Debug("creating environment"); #region Environment Environment Env = new Environment(Log); #endregion Environment #region build plugins // prepare pluginhandlers Env.DrawPlugins.AddPlugin(new DrawPlugin_Background()); // "background R,G,B" where R G B is 0-7 Env.DrawPlugins.AddPlugin(new DrawPlugin_Circle()); // "circle RADIUS" where RADIUS is integer Env.DrawPlugins.AddPlugin(new DrawPlugin_LineTo()); // "lineto x,y" where x y is integer Env.DrawPlugins.AddPlugin(new DrawPlugin_MoveTo()); // "moveto x,y" where x y is integer Env.DrawPlugins.AddPlugin(new DrawPlugin_Rect()); // "rect x,y" where x y is integer Env.DrawPlugins.AddPlugin(new DrawPlugin_Polygon()); // "poly x,y x,y x,y" where x y is integer Env.DrawPlugins.AddPlugin(new DrawPlugin_Color()); // "color R,G,B" where R G B is 0-7 #endregion build plugins Log?.IfDebug?.Debug(@"Plugins loaded: {0}", string.Join(",", Env.DrawPlugins.Values.ToList().ConvertAll <string>(L => string.Join(",", L.ConvertAll <string>(P => string.Format(@"{0}.{1}", P.Vendor, P.Name)).ToArray())).ToArray())); #region build code queue Queue <Command> codeQueue = new Queue <Command>(); foreach (string currentLine in source) { codeQueue.Enqueue(new Command(currentLine)); } #endregion build code queue Log?.IfDebug?.Debug(@"build code queue with {0} commands", codeQueue.Count); #region make canvas Canvas canvas = new Canvas(50, 50, new Color(0, 0, 0)); #endregion make canvas Log?.IfDebug?.Debug(@"created canvas {0}x{1}", canvas.Width, canvas.Height); #region progress codeQueue while (codeQueue.Count > 0) { // break if over limits Command command = codeQueue.Dequeue(); if (Env.TryRunDraw(command, canvas)) { // success Log?.IfDebug?.Debug(@"sucessfully run command ""{0} {1}"" ", command.Key, command.Args); } else { // failed Log?.IfDebug?.Debug(@"failed at command ""{0} {1}"" ", command.Key, command.Args); } } Log?.PopStack(); return(canvas); #endregion progress codeQueue }
/* * This this script does nothing by it's own. * This is a placeholder to keep trak of BMyLog4PB. * * * Please go to http://forums.keenswh.com/threads/log4pb-logging-debugging-lib.7389240/ * for more information. */ public void Main(string argument) { //initialize the logger (logging all kinds of messages to PB's CustomData) BMyLog4PB Log = new BMyLog4PB(this, BMyLog4PB.E_ALL, new BMyLog4PB.BMyCustomDataAppender(this)); Log.Info("This message will appera in this PBs CustomData."); // output all the log messages Log.Flush(); }
public BMyEnvironment(Program Assembly, string arguments) { this.Assembly = Assembly; ArgBag = BaconArgs.parse(arguments); Log = BMyLoggerFactory.getLogger(ArgBag, Assembly); }
private void BootstrapLog(BaconArgs Args) { Log = new BMyLog4PB(this, 0); if (!Args.hasOption("log-noecho")) { Log?.AddAppender(new BMyLog4PB.BMyEchoAppender(this)); } if (Args.hasOption("log-lcd")) { string logLcdTag = Args.getOption("log-lcd")[0]; if (logLcdTag != null) { Log?.AddAppender(new BMyLog4PB.BMyTextPanelAppender(logLcdTag, this)); } } if (Args.hasOption("log-filter") && Args.getOption("log-filter").Count > 0) { log_Filter = 0; foreach (string filterArgValue in Args.getOption("log-filter")) { string[] filterList = filterArgValue.ToLowerInvariant().Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string filter in filterList) { switch (filter) { case "trace": log_Filter |= BMyLog4PB.E_TRACE; break; case "debug": log_Filter |= BMyLog4PB.E_DEBUG; break; case "info": log_Filter |= BMyLog4PB.E_INFO; break; case "warn": log_Filter |= BMyLog4PB.E_WARN; break; case "error": log_Filter |= BMyLog4PB.E_ERROR; break; case "fatal": log_Filter |= BMyLog4PB.E_FATAL; break; case "all": log_Filter |= BMyLog4PB.E_ALL; break; } } } } if (Log != null) { Log.Filter = log_Filter; } }
public Environment(BMyLog4PB Log) { this.Log = Log; DrawPlugins = new PluginBag <DrawPlugin>(this); }