UnixSyslogSupport and embedded line end characters

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

UnixSyslogSupport and embedded line end characters

Randy Coulman
Is anyone else using UnixSyslogSupport from the public Store?

We've been using it, and it's working really well, except for when we try to log a multi-line string with embedded line ends.  These are typically Character cr characters, and so they show up in the syslog as ^M's instead.  syslog() only handles Character lf's properly.

Any thoughts on the best way to convert the line endings into newlines before sending the string to the underlying C API function?  There's the obvious brute-force way, but I'd like something cleaner than that, if possible.

Thanks,
Randy
--
Randy Coulman
[hidden email]

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: UnixSyslogSupport and embedded line end characters

Alan Knight-2
If they go through any sort of external stream in the process you can set the line end convention. Or you could push them through a stream whose line end convention is settable.

On 2011-03-10 6:26 PM, Randy Coulman wrote:
Is anyone else using UnixSyslogSupport from the public Store?

We've been using it, and it's working really well, except for when we try to log a multi-line string with embedded line ends.  These are typically Character cr characters, and so they show up in the syslog as ^M's instead.  syslog() only handles Character lf's properly.

Any thoughts on the best way to convert the line endings into newlines before sending the string to the underlying C API function?  There's the obvious brute-force way, but I'd like something cleaner than that, if possible.

Thanks,
Randy
--
Randy Coulman
[hidden email]
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

-- 
Alan Knight [|], Engineering Manager, Cincom Smalltalk
[hidden email]
[hidden email]
http://www.cincomsmalltalk.com

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: UnixSyslogSupport and embedded line end characters

Randy Coulman
I'd thought of the stream idea - a WriteStream on a String seems like the right idea, but you can't set the lineEndConvention on one of those.  How would you create a stream that has a settable lineEndConvention here?

Syslog>>log:withArgs:priority: is the lowest-level Smalltalk API for this (it calls the C syslog() function) and it just takes a String as its argument - there's no streaming involved anywhere, so I'd have to introduce it somewhere

Randy

On Fri, Mar 11, 2011 at 7:50 AM, Alan Knight <[hidden email]> wrote:
If they go through any sort of external stream in the process you can set the line end convention. Or you could push them through a stream whose line end convention is settable.


On 2011-03-10 6:26 PM, Randy Coulman wrote:
Is anyone else using UnixSyslogSupport from the public Store?

We've been using it, and it's working really well, except for when we try to log a multi-line string with embedded line ends.  These are typically Character cr characters, and so they show up in the syslog as ^M's instead.  syslog() only handles Character lf's properly.

Any thoughts on the best way to convert the line endings into newlines before sending the string to the underlying C API function?  There's the obvious brute-force way, but I'd like something cleaner than that, if possible.

Thanks,
Randy
--
Randy Coulman
[hidden email]
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

-- 
Alan Knight [|], Engineering Manager, Cincom Smalltalk
[hidden email]
[hidden email]
http://www.cincomsmalltalk.com

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc




--
Randy Coulman
[hidden email]

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: UnixSyslogSupport and embedded line end characters

Michael Lucas-Smith-2
To control the lineEnd characters, you'd need to transform characters in to bytes with an EncodedStream. This is where you'll find the lineEndConvention: API. The important distinction here is that characters, CR is newline. In binary, a newline can be encoded anywhich way for the character encoding binary format.. as well as the actual line end convention. Eg: if you encoded in to UTF16 on Windows, you'd have four bytes 0 13 0 10 to specify a line end. UTF8 with the unix convention would be one byte of 10.

Michael

On Mar 11, 2011, at 8:20 AM, Randy Coulman wrote:

I'd thought of the stream idea - a WriteStream on a String seems like the right idea, but you can't set the lineEndConvention on one of those.  How would you create a stream that has a settable lineEndConvention here?

Syslog>>log:withArgs:priority: is the lowest-level Smalltalk API for this (it calls the C syslog() function) and it just takes a String as its argument - there's no streaming involved anywhere, so I'd have to introduce it somewhere

Randy

On Fri, Mar 11, 2011 at 7:50 AM, Alan Knight <[hidden email]> wrote:
If they go through any sort of external stream in the process you can set the line end convention. Or you could push them through a stream whose line end convention is settable.


On 2011-03-10 6:26 PM, Randy Coulman wrote:
Is anyone else using UnixSyslogSupport from the public Store?

We've been using it, and it's working really well, except for when we try to log a multi-line string with embedded line ends.  These are typically Character cr characters, and so they show up in the syslog as ^M's instead.  syslog() only handles Character lf's properly.

Any thoughts on the best way to convert the line endings into newlines before sending the string to the underlying C API function?  There's the obvious brute-force way, but I'd like something cleaner than that, if possible.

Thanks,
Randy
--
Randy Coulman
[hidden email]
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

-- 
Alan Knight [|], Engineering Manager, Cincom Smalltalk
[hidden email]
[hidden email]
http://www.cincomsmalltalk.com

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc




--
Randy Coulman
[hidden email]
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: UnixSyslogSupport and embedded line end characters

Michael Lucas-Smith-2
In reply to this post by Randy Coulman
>
> Syslog>>log:withArgs:priority: is the lowest-level Smalltalk API for this (it calls the C syslog() function) and it just takes a String as its argument - there's no streaming involved anywhere, so I'd have to introduce it somewhere
>

As another point here - it's generally incorrect to give a String object of any kind to a C call that expects char*. The VM doesn't know what encoding the C string should be and it varies from library to library. So by first encoding your smalltalk strings in to a bytearray with the encoding you know the C library uses, you'll avoid problems down the road.

Michael
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc