Logging facility for GNU-smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Re: Logging facility for GNU-smalltalk

Paolo Bonzini-3

>> Agreed, that's the point of the output handler no?  My idea of the class
>> hierarchy would be:
>>
>>    OutputHandler
>>      StreamOutputHandler
>>        TextOutputHandler
>>        HTMLOutputHandler
>>      SyslogOutputHandler
>
> I don't know anything about how to talk to a syslogd. Why can
> SyslogOutputHandler not be a StreamOutputHandler?

You use the syslog(3) function directly, which handles priorities as a
separate argument rather than as part of the message.

        void openlog(const char *ident, int option, int facility);
        void syslog(int priority, const char *format, ...);
        void closelog(void);

But alternatively, you could use a socket connected to UDP port 514,
which would indeed be a stream.  That's cool too.

> Want your messages plain text? That's the default.
> As HTML? Use a HTMLFiter.
> Have them spelled backwards? Go develop your ReversingFilter yourself.
>
> It might also be possible that I'm talking about exactly the same thing
> as Paolo, only with different words.

More or less.  You're adding a DecoratorOutputHandler to the hierarchy
above.

I'm not sure whether HTML fits under DecoratorOutputHandler or
StreamOutputHandler.  Definitely ReversingOutputHandler would be a
decorator, but I hadn't thought about it. :-)

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Logging facility for GNU-smalltalk

Jan Vrany-2
In reply to this post by Joachim Jaeckel
Hello,

it seems that there is plenty of logging tools for Smalltalk.
We have created our own called Loggia
(public SVN http://smalltalk.felk.cvut.cz/svn/stx/goodies/loggia,
written for Smalltalk/X) and at ESUG 2007 in Lugano somebody
presents another logging tool - unfortunately I forgot the name,
but it was for VW and should be in public repository.

Looking at the documentation, all three tools are designed
in pretty same way.

Happy logging :-) Jan

Cituji Joachim Jaeckel <[hidden email]>:

> Hello,
>
> in the last week, I created a small logging facility which could be  
> used with GNU-smalltalk. (Because I haven't found something like the  
> logging api from Java for Smalltalk and I was tired using 'xyz'  
> printNl's. ...)
>
> I don't know, if you have a usage for it, or if you in generall  
> interested in it, but please allow me to describe it a little bit.
>
> --
>
> For reading the bit of documentation, please visit:
> http://www.joachim-jaeckel.de/redmine/wiki/log4gst
>
> For the case, you would like to download it, try:
> svn co svn://www.joachim-jaeckel.de/repos/log4gst/trunk Logging
>
>
> It consists of a LogManager, which is available via  
> Log4Gst.LogManager instance. It's implemented as a singleton, so  
> there's only one instance in a smalltalk-vm.
>
> This LogManager can handle different instances of loggers (available  
> via logManager logger: 'CategoryXYZ'). These loggers are identified  
> through category-names. (The idea behind is, that e.g. if you have  
> several different applications running in the same vm, that every  
> application could have it's own logger...)
>
> Each logger itself can have different output "channels", these  
> "channels" could be constructed via an output-handler (like a  
> transcript-output-handler or a file-output-handler) and a special  
> formatter (like a text-formatter or a html-formatter).
>
> This gives you the possiblity, to log directly with a text-format to  
> the transcript and parallel in html-format to an html-file. Or you  
> could subclass your own output-handler and formatter and provide  
> some completely new outputs and formats of the messages.
>
> There exists 6 different kind of messages, which could be printed.  
> (SEVERE, WARNING, INFO, FINE, FINER, FINEST).
> (Additionally, there are defined NONE and ALL, where ALL means the  
> same as FINEST...)
>
> For the logger and for every configured channel, you can set the  
> output-severity of them independently.
> The severity which could be set for the logger itself, controls the  
> output of messages, which should be printed in general through this  
> logger. The severity which could be set for each channel, controls  
> the output of messages, which should be printed through this channel.
>
> A log-message is automatically enhanced by the category of the  
> logger, the date and time of printing the log-message, and the class  
> and method-name, from which the logging is called. Of course, you  
> can control the information which is printed through several  
> different implementations of the different formatters, or write your  
> own one.
>
> Best regards,
> Joachim.
>
>
> _______________________________________________
> help-smalltalk mailing list
> [hidden email]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>





_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Logging facility for GNU-smalltalk

Joachim Jaeckel
In reply to this post by Paolo Bonzini-3
Paolo Bonzini schrieb:

> My idea of the class hierarchy would be:
>
>   OutputHandler
>     StreamOutputHandler
>       TextOutputHandler
>       HTMLOutputHandler
>     SyslogOutputHandler
>     MultiplexOutputHandler
>
> (Of course not everything needs to be there to include the logging in gst).
>
> What do you think?

Hi!

Ok, here I see, that an OutputHandler for you is the combination of (in
the case of my logging currently implemented) a formatter and an Output
(or Log-) Handler. (Which is called "channel" in my current
implementation. This is currently not an Object, just a Dictionary with
the fields for outputSeverity, logHandler and formatter).

I think I should explain in short, how my logging is currently working.

A logger for a category could have several output-channels, which could
be active for the same time. (if you have several channels active
[output-severity > NONE], a single log-message is printed on each of the
channels).

Each channel is a combination of a LogHandler (currently to a File or to
the transcript, in future even to a stream) and a selected formatter
(text or html-format currently) you can combine the formatter and the
logHandler as you like, so that you could log in html to the transcript
or (with the stream) to a socket. (Or you'll could handle the stream by
your own).
(or you can implement your own logHandler or formatter and provide an
instance of it to the channel)
The formatter accepts a LogEntry-Object(*) as the input and returns a
string of the log-information. The logHandler accepts the string and
direct it to the desired output.
So the code of the log-message output for each channel is like this:

logHandler log: (formatter format: logEntry).

(Ok, there's additionally a switch for determine, if the output to this
channel has already started, for the start and end work for each
formatting and output, but that's only a detail...)

- Do you think, that this what currently is implemented as only a
Dictionary should go into the former mentioned class-hierachy of objects?

- Maybe I would need some more information, of how you think the
decorators should work...

(*)
The log-method itselfs creates eventually an Object (I would say a
ValueObject) with the information of the message.

The call would be: "logger logError: 'This is an error'." and the
log-method would generate an Object with the infos:
- category
- date
- time
- severity
- classname in which the logError was called  ---
- methodname in which the logError was called    |
- filename                                       |
- line                                            > got from the context
- lineInFile                                     |
- message                                     ---


(Hope I haven't wrote too much...)

Regards,
Joachim.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Logging facility for GNU-smalltalk

Paolo Bonzini-3
On 07/10/2009 12:25 PM, Joachim Jaeckel wrote:
> Ok, here I see, that an OutputHandler for you is the combination of (in
> the case of my logging currently implemented) a formatter and an Output
> (or Log-) Handler.

I think for me the OutputHandler is indeed the combination of your
LogHandler and a formatter, with the difference that Transcript, file,
etc. for me are all realized with the same kind of LogHandler; possibly
created with different class methods.

 > So the code of the log-message output for each channel is like this:
 >
 > logHandler log: (formatter format: logEntry).

The problem with this is that in some cases the LogHandler might need
the severity and category, as is the case for syslog (and I expect
special handling of date/time in some cases might be desirable, for
example to put a limit on the number of messages per second).

 > - Do you think, that this what currently is implemented as only a
 > Dictionary should go into the former mentioned class-hierachy of
 > objects?

It could be done entirely with a MultiplexOutputHandler that also takes
care about filtering unwanted severities, yes.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Logging facility for GNU-smalltalk

Joachim Jaeckel
> I think for me the OutputHandler is indeed the combination of your
> LogHandler and a formatter, with the difference that Transcript, file,
> etc. for me are all realized with the same kind of LogHandler; possibly
> created with different class methods.

Aha.

>  > logHandler log: (formatter format: logEntry).
>
> The problem with this is that in some cases the LogHandler might need
> the severity and category, as is the case for syslog (and I expect
> special handling of date/time in some cases might be desirable, for
> example to put a limit on the number of messages per second).

Ok, seems reasonable, what about
logHandler log: LogEntry formattedMsg: (formatter format: logEntry).

So you have all the data like category, severity, date and time
available to the logHandler.

> It could be done entirely with a MultiplexOutputHandler that also takes
> care about filtering unwanted severities, yes.

filtering unwanted severities is currently done in the logger itself
(which is the only class with a bit of logic) because the Dictionary for
the channel holds the output-severity for this channel. The other
classes (LogHandler and Formatter) are really dumb and plugable to the
channel.

I thought about moving the channel-handling in a seperate class, that
makes the responsibility a bit clearer, that the channel-handler is also
responsable for the output-severity of this channel... but than, I
decided to keep this little logic also in the logger itself  instead of
creating an additional step of communication to the log-output.

...maybe I should change that...

And the MultiplexOutputHandler sounds to me like my Logger, with the
difference, that you format the message only once and redirect it to the
several available streams.


Regards,
Joachim.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Logging facility for GNU-smalltalk

Paolo Bonzini-3
On 07/10/2009 07:51 PM, Joachim Jaeckel wrote:

>> I think for me the OutputHandler is indeed the combination of your
>> LogHandler and a formatter, with the difference that Transcript, file,
>> etc. for me are all realized with the same kind of LogHandler;
>> possibly created with different class methods.
>
> Aha.
>
>> > logHandler log: (formatter format: logEntry).
>>
>> The problem with this is that in some cases the LogHandler might need
>> the severity and category, as is the case for syslog (and I expect
>> special handling of date/time in some cases might be desirable, for
>> example to put a limit on the number of messages per second).
>
> Ok, seems reasonable, what about
> logHandler log: LogEntry formattedMsg: (formatter format: logEntry).
>
> So you have all the data like category, severity, date and time
> available to the logHandler.

Then why don't you move the formatter instance variable to the logHandler?

> ...maybe I should change that...
>
> And the MultiplexOutputHandler sounds to me like my Logger, with the
> difference, that you format the message only once and redirect it to the
> several available streams.

Indeed.  The idea of decorators is exactly to move stuff out of the
logger to its users by putting some other output handler between the
logger and what actually writes the output.  The decorator can do
filtering but otherwise delegates the output to the leaf.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Re: Logging facility for GNU-smalltalk

Göran Krampe
In reply to this post by Paolo Bonzini-3
Hi!

Just wanted to mention SimpleLog on SqueakMap, I modelled it after
syslog (levels etc) and it has an UDP syslog backend (very little code).

I use the approach of a Singleton instance (or you can go to an instance
of SLLog directly if you like) and then the class (SLLog) has mirrored
the protocol on the class side so that you can type:

        SLLog error: 'blabla'

(or warn:, notice: etc)

Then the SLLog instance has an OrderedCollection of "emitters" that it
uses to actually do some output, thus you can easily log onto a file,
Transcript and onto syslog at the same time if you like. It even has
file rotation :)

Feel free to port it if you want, it should be small and straight
forward, it is here (under new BSD):

        http://map.squeak.org/packagebyname/SimpleLog

regards, Göran



_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
12