There are many ways to approach this - yours seems to be one reasonable method.

Another way might be to use a centralised logging module which used a singleton approach to do something similar. The advantage here is that by delaying the openlog to the first call, you may go through an entire execution without ever opening the log - which may or may not be of significance. There would only be one call to openlog in your entire program because they would all go through MyLogger::logthis() - which would open the log if it wasn't already open. Then, using the magic of singletons, the DESTROY method would close it, or you could use the END block as above to detect if the log was opened, and, if so, then close it.

I suppose a method that maps closest to how you developed procedurally would have the advantage of being a philosophy close to what you're used to, so my question is - before you tried the magic of OO, how did you use syslog?

Update: The above was written before the real problem appeared in Zarathustra's update. The error message seems to say that your syslog.h doesn't have a macro required for this to work - that's a compile-time problem, not a run-time problem. Does your non-module use of syslog work on this same machine? What platform is it?


In reply to Re: Sys::Syslog in OOP Module by Tanktalus
in thread Sys::Syslog in OOP Module by Zarathustra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.