Another Log implementation

Daniel Gibson metalcaedes at gmail.com
Mon May 30 02:22:39 PDT 2011


Am 30.05.2011 11:18, schrieb Vincent:
> On Mon, 30 May 2011 01:32:44 +0200, Daniel Gibson
> <metalcaedes at gmail.com> wrote:
> 
>> So if it's just "EmailLogEngine" or whatever and it's using SMTP,
>> changing it to use the SMTP-alternative....
> 
> It's just a wrong view on a whole conception. Log uses different KIND of
> targets: file, database(do you care which one??), mail (is it important
> which proto??), etc.
> 'Mail' is an abstraction of "something which can send message to the
> human". So... instead of making annoying set of classes for all known
> mail protocols, we use ONE mail class with appropriate constructors for
> all imaginable protocols. Say:
> 
> enum MailProto { SMTP, IMAP }
> 
> class EmailLogEngine : LogEngine
> {
>     public this(MailProto type, string user, string psw, string host,
> int port = 0)
>     {
>         if (port == 0)
>             switch(type) {
>             case SMTP: port = 25; break;
>             }
> 
>         // initialize mail server structures
>     }
> 
>     override public void Write(string msg)
>     {
>         // send message, using appropriate proto
>     }
> }

How is
auto logCrash = new Log(new EmailLogEngine(MailProto.SMTP,
"smtp.myserver.com"));
better than
auto logCrash = new Log(new SMPTLogEngine("smtp.myserver.com")); ?


More information about the Digitalmars-d mailing list