Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31896

Re: basic output question

Newsgroups comp.lang.java.programmer
Date 2015-06-30 12:14 -0700
References <635be647-55fb-43f9-8609-0320306ca853@googlegroups.com> <450dd941-b331-4f46-9e9c-e7db4033e0ca@googlegroups.com> <mmu43k$tkm$1@dont-email.me> <91961835-9633-4c29-968d-027ce3fb9ff7@googlegroups.com> <5592e61d$0$292$14726298@news.sunsite.dk>
Message-ID <16cd77ab-e259-40b5-8599-de59a7db5dbd@googlegroups.com> (permalink)
Subject Re: basic output question
From e.d.programmer@gmail.com

Show all headers | View raw


> >>> On Monday, June 29, 2015 at 2:40:05 PM UTC-4, Russ P. wrote:
> >>>> So if I call printInformation with no arguments, the output
> >>>> goes to standard output, but if I give it a filename the output
> >>>> goes to the file. Is this the best way to do it, or is there a
> >>>> simpler/better way? I'd also like to be able to append the
> >>>> output to an existing file as well as create a new file.
> >>>> Thanks.
> >>>
> >>> I never quite got the logging frameworks ie commons logging.
> >>
> >> s/ie/eg/
> >>
> >>> You have to deal with someone else's API, [...]
> >>
> >> That's called "component reuse," and most people think of it as a
> >> Good Thing.  In moderation, of course.
> >>
> >>> [...] set warning levels, and include an extra jar in the
> >>> classpath. [...]
> >>
> >> There's also the built-in java.util.logging package, assuming
> >> you're using a post-2002 Java version.
> >
> > Most people seem to be using the Apache Commons Logging.  I'm not
> > sure why.
> 
> It allows the code to be used with a different actual logging framework
> with no code changes.
> 
> >     I just looked at java.util.logging.Logger and most of that
> > seems irrelevant when all you want to do is write messages to
> > System.out.
> 
> Usually people at some point end up needing to do something
> more advanced that just writing to System.out.
> 
> OP already reached that level.
> 
> >             In my static log class I just add the timestamp and
> > calling method and line number to every output line.  I don't want to
> > get an instance of a logger object for every line to print much less
> > configure a handler or assign a level.
> 
> Rolling file appenders, syslog integration, the ability to adjust
> log level etc. are important in most big applications.
> 
> Arne

OP mentioned wanting to do System.out.println().  java.util.logging.Logger is not static, so if you want to write a single statement to create a log message without creating a new instance of an object it makes sense to write your own.  If you write your own logging class it makes sense to have your own class to write text files.  If you want to get an instance every time, if you want a logging API to open a log file for you, if it can keep it open to append while you're running and close it automatically when you're done, it might make sense to use the API.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

basic output question "Russ P." <russ.paielli@gmail.com> - 2015-06-29 11:39 -0700
  Re: basic output question Arne Vajhøj <arne@vajhoej.dk> - 2015-06-29 14:53 -0400
  Re: basic output question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-29 15:32 -0400
  Re: basic output question e.d.programmer@gmail.com - 2015-06-30 05:45 -0700
    Re: basic output question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-30 09:05 -0400
      Re: basic output question e.d.programmer@gmail.com - 2015-06-30 11:28 -0700
        Re: basic output question Arne Vajhøj <arne@vajhoej.dk> - 2015-06-30 14:55 -0400
          Re: basic output question e.d.programmer@gmail.com - 2015-06-30 12:14 -0700
            Re: basic output question Arne Vajhøj <arne@vajhoej.dk> - 2015-07-27 22:25 -0400
        Re: basic output question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-30 15:27 -0400

csiph-web