1 // Kelsier project - Logging code (Logger.cs)
2 // Written by the Jobbig codeteam. <http://jobbig.eu/code/>
3 // Copyright 2013 John Runyon.
5 // This file is part of the Kelsier project.
7 // Kelsier is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 using System.Collections.Generic;
29 public LogOutput[] debugs {get; private set; }
30 public LogOutput[] infos { get; private set; }
31 public LogOutput[] errors { get; private set; }
32 public string from { get; private set; }
35 /// Construct a Logger, writing to the specified TextWriter objects. Use an empty array to disable an output.
37 /// <param name="debugs">Array of TextWriter's to use for debug output</param>
38 /// <param name="infos">...for info output</param>
39 /// <param name="errors">...for error output</param>
40 public Logger(string from, LogOutput[] debugs, LogOutput[] infos, LogOutput[] errors) {
42 if (Int32.TryParse(from, out fromid)) {
43 this.from = fromid.ToString("0000");
53 this.debug("Starting Root logging (debug) here at "+DateTime.Now.ToString("F"));
54 this.info("Starting Root logging (info) here at "+DateTime.Now.ToString("F"));
55 this.error("Starting Root logging (error) here at "+DateTime.Now.ToString("F"));
58 public Logger(string from, Logger copy) {
61 this.debugs = copy.debugs;
62 this.infos = copy.infos;
63 this.errors = copy.infos;
69 /// <param name="msg">Log message (with formatting placeholders, if desired)</param>
70 /// <param name="args">Formatting replacements.</param>
71 public void debug(object msg) {
72 foreach (LogOutput outw in debugs) {
74 outw.writer.WriteLine("(D@" + DateTime.Now.ToString("HH:mm:ss") + ")[" + from + "] " + msg.ToString());
81 /// <param name="msg">Log message (with formatting placeholders, if desired)</param>
82 /// <param name="args">Formatting replacements.</param>
83 public void info(object msg) {
84 foreach (LogOutput outw in infos) {
86 outw.writer.WriteLine("(I@" + DateTime.Now.ToString("HH:mm:ss") + ")[" + from + "] " + msg.ToString());
93 /// <param name="msg">Log message (with formatting placeholders, if desired)</param>
94 /// <param name="args">Formatting replacements.</param>
95 public void error(object msg) {
96 foreach (LogOutput outw in errors) {
98 outw.writer.WriteLine("(E@" + DateTime.Now.ToString("HH:mm:ss") + ")[" + from + "] " + msg.ToString());
104 public TextWriter writer { get; private set; }
106 public LogOutput(TextWriter writer) {
107 this.writer = writer;