You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Matt Sicker <bo...@gmail.com> on 2014/03/23 23:58:32 UTC

Would like to change a bit of the SimpleLogger API. Feedback requested.

Would it be alright to migrate to using PrintWriter instead of PrintStream?
This improves charset handling, plus Java recommends using Writers over
OutputStreams for textual content.

-- 
Matt Sicker <bo...@gmail.com>

Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Matt Sicker <bo...@gmail.com>.
Good point. So in order to add configurable charset support, it would be
best to continue using streams instead of writers. The character set should
probably be stored in SimpleLoggerContext. I don't remember if specific
charset support is already there for core.Logger[Context], so that might be
worth looking into as well down the line.


On 24 March 2014 20:23, Bruce Brouwer <br...@gmail.com> wrote:

> I think it should remain a PrintStream. The PrintWriter still uses a
> charset by defaulting to the platform encoding, but you have no way to
> choose it unless you specify that you are writing to a file. I think
> PrintWriter needs some more constructor options when giving it an
> OutputStream, but that's just my opinion. At least with PrintWriter you
> have the option to choose the charset when giving it an OutputStream.
>
> What might make sense is to change the SimpleLoggerContext constructor to
> pull out the charset name from the props when falling into the case where
> it is creating a FileOutputStream. All you need to change is the line that
> currently reads like this:
>
> ps = new PrintStream(os);
>
> change it to something like this:
>
> final String charset =
> props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "charset");
> if (charset != null) {
>   ps = new PrintStream(os, false, charset);
> } else {
>   ps = new PrintStream(os);
> }
>
> That will need another catch block, but that shouldn't be a big problem to
> figure out.
>
>
>
> On Mon, Mar 24, 2014 at 12:20 AM, Matt Sicker <bo...@gmail.com> wrote:
>
>> From what I can tell, it's when you use OutputStream instead of Writer
>> that you need to specify charsets. I think the writers have a more friendly
>> configuration mechanism just via Java properties or something. I'm not
>> fully sure, actually.
>>
>>
>> On 23 March 2014 23:09, Ralph Goers <ra...@dslextreme.com> wrote:
>>
>>> For StatusLogger you would then have to add a charset attribute to the
>>> configuration element wouldn’t you?
>>>
>>> Ralph
>>>
>>> On Mar 23, 2014, at 7:09 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>> It's mainly for StatusLogger, but that idea did cross my mind.
>>>
>>>
>>> On 23 March 2014 21:00, Ralph Goers <ra...@dslextreme.com> wrote:
>>>
>>>> I’m sorry, I didn’t ask the question correctly.  SimpleLogger doesn’t
>>>> currently accept a charset. Are you planning on adding a new properly to
>>>> SimpleLoggerContext to support this?  I don’t really have an objection but
>>>> am just wondering when other than the platform’s default encoding would
>>>> want to be used. After all, SimpleLogger wasn’t really meant to be what
>>>> people actually used on purpose.
>>>>
>>>> Ralph
>>>>
>>>> On Mar 23, 2014, at 6:01 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>>
>>>> It's right there in the docs:
>>>> http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html
>>>>
>>>> All characters printed by a PrintStream are converted into bytes using
>>>> the platform's default character encoding. The PrintWriter<http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html> class
>>>> should be used in situations that require writing characters rather than
>>>> bytes.
>>>>
>>>>
>>>> On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:
>>>>
>>>>> How will it improve charset handling?  Currently a charset isn’t
>>>>> configured.
>>>>>
>>>>> Ralph
>>>>>
>>>>> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>>>
>>>>> Would it be alright to migrate to using PrintWriter instead of
>>>>> PrintStream? This improves charset handling, plus Java recommends using
>>>>> Writers over OutputStreams for textual content.
>>>>>
>>>>> --
>>>>> Matt Sicker <bo...@gmail.com>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>>
>>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
>
> --
>
> Bruce Brouwer
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Bruce Brouwer <br...@gmail.com>.
I think it should remain a PrintStream. The PrintWriter still uses a
charset by defaulting to the platform encoding, but you have no way to
choose it unless you specify that you are writing to a file. I think
PrintWriter needs some more constructor options when giving it an
OutputStream, but that's just my opinion. At least with PrintWriter you
have the option to choose the charset when giving it an OutputStream.

What might make sense is to change the SimpleLoggerContext constructor to
pull out the charset name from the props when falling into the case where
it is creating a FileOutputStream. All you need to change is the line that
currently reads like this:

ps = new PrintStream(os);

change it to something like this:

final String charset =
props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "charset");
if (charset != null) {
  ps = new PrintStream(os, false, charset);
} else {
  ps = new PrintStream(os);
}

That will need another catch block, but that shouldn't be a big problem to
figure out.



On Mon, Mar 24, 2014 at 12:20 AM, Matt Sicker <bo...@gmail.com> wrote:

> From what I can tell, it's when you use OutputStream instead of Writer
> that you need to specify charsets. I think the writers have a more friendly
> configuration mechanism just via Java properties or something. I'm not
> fully sure, actually.
>
>
> On 23 March 2014 23:09, Ralph Goers <ra...@dslextreme.com> wrote:
>
>> For StatusLogger you would then have to add a charset attribute to the
>> configuration element wouldn't you?
>>
>> Ralph
>>
>> On Mar 23, 2014, at 7:09 PM, Matt Sicker <bo...@gmail.com> wrote:
>>
>> It's mainly for StatusLogger, but that idea did cross my mind.
>>
>>
>> On 23 March 2014 21:00, Ralph Goers <ra...@dslextreme.com> wrote:
>>
>>> I'm sorry, I didn't ask the question correctly.  SimpleLogger doesn't
>>> currently accept a charset. Are you planning on adding a new properly to
>>> SimpleLoggerContext to support this?  I don't really have an objection but
>>> am just wondering when other than the platform's default encoding would
>>> want to be used. After all, SimpleLogger wasn't really meant to be what
>>> people actually used on purpose.
>>>
>>> Ralph
>>>
>>> On Mar 23, 2014, at 6:01 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>> It's right there in the docs:
>>> http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html
>>>
>>> All characters printed by a PrintStream are converted into bytes using
>>> the platform's default character encoding. The PrintWriter<http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html> class
>>> should be used in situations that require writing characters rather than
>>> bytes.
>>>
>>>
>>> On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:
>>>
>>>> How will it improve charset handling?  Currently a charset isn't
>>>> configured.
>>>>
>>>> Ralph
>>>>
>>>> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>>
>>>> Would it be alright to migrate to using PrintWriter instead of
>>>> PrintStream? This improves charset handling, plus Java recommends using
>>>> Writers over OutputStreams for textual content.
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>>
>>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 

Bruce Brouwer

Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Matt Sicker <bo...@gmail.com>.
>From what I can tell, it's when you use OutputStream instead of Writer that
you need to specify charsets. I think the writers have a more friendly
configuration mechanism just via Java properties or something. I'm not
fully sure, actually.


On 23 March 2014 23:09, Ralph Goers <ra...@dslextreme.com> wrote:

> For StatusLogger you would then have to add a charset attribute to the
> configuration element wouldn’t you?
>
> Ralph
>
> On Mar 23, 2014, at 7:09 PM, Matt Sicker <bo...@gmail.com> wrote:
>
> It's mainly for StatusLogger, but that idea did cross my mind.
>
>
> On 23 March 2014 21:00, Ralph Goers <ra...@dslextreme.com> wrote:
>
>> I’m sorry, I didn’t ask the question correctly.  SimpleLogger doesn’t
>> currently accept a charset. Are you planning on adding a new properly to
>> SimpleLoggerContext to support this?  I don’t really have an objection but
>> am just wondering when other than the platform’s default encoding would
>> want to be used. After all, SimpleLogger wasn’t really meant to be what
>> people actually used on purpose.
>>
>> Ralph
>>
>> On Mar 23, 2014, at 6:01 PM, Matt Sicker <bo...@gmail.com> wrote:
>>
>> It's right there in the docs:
>> http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html
>>
>> All characters printed by a PrintStream are converted into bytes using
>> the platform's default character encoding. The PrintWriter<http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html> class
>> should be used in situations that require writing characters rather than
>> bytes.
>>
>>
>> On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:
>>
>>> How will it improve charset handling?  Currently a charset isn’t
>>> configured.
>>>
>>> Ralph
>>>
>>> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>> Would it be alright to migrate to using PrintWriter instead of
>>> PrintStream? This improves charset handling, plus Java recommends using
>>> Writers over OutputStreams for textual content.
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>>
>>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Ralph Goers <ra...@dslextreme.com>.
For StatusLogger you would then have to add a charset attribute to the configuration element wouldn’t you?

Ralph

On Mar 23, 2014, at 7:09 PM, Matt Sicker <bo...@gmail.com> wrote:

> It's mainly for StatusLogger, but that idea did cross my mind.
> 
> 
> On 23 March 2014 21:00, Ralph Goers <ra...@dslextreme.com> wrote:
> I’m sorry, I didn’t ask the question correctly.  SimpleLogger doesn’t currently accept a charset. Are you planning on adding a new properly to SimpleLoggerContext to support this?  I don’t really have an objection but am just wondering when other than the platform’s default encoding would want to be used. After all, SimpleLogger wasn’t really meant to be what people actually used on purpose.
> 
> Ralph
> 
> On Mar 23, 2014, at 6:01 PM, Matt Sicker <bo...@gmail.com> wrote:
> 
>> It's right there in the docs:
>> http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html
>> 
>> All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.
>> 
>> 
>> On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:
>> How will it improve charset handling?  Currently a charset isn’t configured.
>> 
>> Ralph
>> 
>> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
>> 
>>> Would it be alright to migrate to using PrintWriter instead of PrintStream? This improves charset handling, plus Java recommends using Writers over OutputStreams for textual content.
>>> 
>>> -- 
>>> Matt Sicker <bo...@gmail.com>
>> 
>> 
>> 
>> 
>> -- 
>> Matt Sicker <bo...@gmail.com>
> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Matt Sicker <bo...@gmail.com>.
It's mainly for StatusLogger, but that idea did cross my mind.


On 23 March 2014 21:00, Ralph Goers <ra...@dslextreme.com> wrote:

> I’m sorry, I didn’t ask the question correctly.  SimpleLogger doesn’t
> currently accept a charset. Are you planning on adding a new properly to
> SimpleLoggerContext to support this?  I don’t really have an objection but
> am just wondering when other than the platform’s default encoding would
> want to be used. After all, SimpleLogger wasn’t really meant to be what
> people actually used on purpose.
>
> Ralph
>
> On Mar 23, 2014, at 6:01 PM, Matt Sicker <bo...@gmail.com> wrote:
>
> It's right there in the docs:
> http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html
>
> All characters printed by a PrintStream are converted into bytes using
> the platform's default character encoding. The PrintWriter<http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html> class
> should be used in situations that require writing characters rather than
> bytes.
>
>
> On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:
>
>> How will it improve charset handling?  Currently a charset isn’t
>> configured.
>>
>> Ralph
>>
>> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
>>
>> Would it be alright to migrate to using PrintWriter instead of
>> PrintStream? This improves charset handling, plus Java recommends using
>> Writers over OutputStreams for textual content.
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Ralph Goers <ra...@dslextreme.com>.
I’m sorry, I didn’t ask the question correctly.  SimpleLogger doesn’t currently accept a charset. Are you planning on adding a new properly to SimpleLoggerContext to support this?  I don’t really have an objection but am just wondering when other than the platform’s default encoding would want to be used. After all, SimpleLogger wasn’t really meant to be what people actually used on purpose.

Ralph

On Mar 23, 2014, at 6:01 PM, Matt Sicker <bo...@gmail.com> wrote:

> It's right there in the docs:
> http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html
> 
> All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.
> 
> 
> On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:
> How will it improve charset handling?  Currently a charset isn’t configured.
> 
> Ralph
> 
> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
> 
>> Would it be alright to migrate to using PrintWriter instead of PrintStream? This improves charset handling, plus Java recommends using Writers over OutputStreams for textual content.
>> 
>> -- 
>> Matt Sicker <bo...@gmail.com>
> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Matt Sicker <bo...@gmail.com>.
It's right there in the docs:
http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html

All characters printed by a PrintStream are converted into bytes using the
platform's default character encoding. The
PrintWriter<http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html>
class
should be used in situations that require writing characters rather than
bytes.


On 23 March 2014 18:54, Ralph Goers <ra...@dslextreme.com> wrote:

> How will it improve charset handling?  Currently a charset isn’t
> configured.
>
> Ralph
>
> On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:
>
> Would it be alright to migrate to using PrintWriter instead of
> PrintStream? This improves charset handling, plus Java recommends using
> Writers over OutputStreams for textual content.
>
> --
> Matt Sicker <bo...@gmail.com>
>
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: Would like to change a bit of the SimpleLogger API. Feedback requested.

Posted by Ralph Goers <ra...@dslextreme.com>.
How will it improve charset handling?  Currently a charset isn’t configured.

Ralph

On Mar 23, 2014, at 3:58 PM, Matt Sicker <bo...@gmail.com> wrote:

> Would it be alright to migrate to using PrintWriter instead of PrintStream? This improves charset handling, plus Java recommends using Writers over OutputStreams for textual content.
> 
> -- 
> Matt Sicker <bo...@gmail.com>