Hey Jonathan,

the log4j configuration is more of interest for your case. However, as
you now got output, I assume the logging itself is working.

Your double entries - for that i am pretty sure - come from the additivity flag.

Please go to: http://logging.apache.org/log4j/1.2/manual.html
and search for "Appender Additivity"

This will help you

cheers


On Sun, Apr 24, 2011 at 1:17 PM, Jonathan Camilleri
<[email protected]> wrote:
> Well thanks for the information about pom.xml, I'm trying to stick with
> log4j.properties, so I'm attaching a copy of my cmd.log - command line log.
> I've encountered another weird problem when trying to review the output of
> Apache log 4j on the console, since some how lines are being written
> multiple times, although I suspect this has to do with looping through an
> ArrayList (a java problem), however, I am not sure, because I haven't
> noticed any flaws in my code:
> Code
> package poker;
> import java.awt.Image;
> import java.io.BufferedInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.*;
> import javax.imageio.ImageIO;
> import org.apache.log4j.BasicConfigurator;
> import org.apache.log4j.Logger;
> public class Poker {
> public static void main(String[] args) {
> BasicConfigurator.configure();
> ...
> Player playerOne = new Player("Player One");
> playerOne.getCardFromDealer(getTopCard());
> playerOne.getCardFromDealer(getTopCard());
> _log.debug(playerOne + ".");
> _log.debug(playerOne.hashCode());
> Player playerTwo = new Player("Player Two");
> playerTwo.getCardFromDealer(getTopCard());
> playerTwo.getCardFromDealer(getTopCard());
> _log.debug(playerTwo + ".");
> _log.debug(playerTwo.hashCode());
> ...
> for (int i = 0; i < deckOfCards.size(); i++) {
> _log.debug(deckOfCards.get(i));}
> }
> private static void getCards (boolean _shuffled) {
> short iCount = 0;
> for (short suit = 1; suit <= MAX_SUITS_IN_DECK; suit++){
> for (short rank = 1; rank <= MAX_RANK_IN_DECK; rank++) {
> deckOfCards.add(new Card(suit, rank));
> iCount++;
> }}
> if (_shuffled == true){Collections.shuffle(deckOfCards, new Random());}
> }
>
> private static Card getTopCard() {
> Card _cardRemoved = deckOfCards.get(1);
> deckOfCards.remove(1);
> return _cardRemoved;
> }
> private static void readIcons(){
>      String _filename;
>      //read icons
>      Image _image = null;
>      File _file = null;
>      InputStream _is = null;
>      for (int i = 1; i < MAX_CARDS_IN_DECK + 1; i++) {
>      try {
>      /* Security information: filenames should not be altered manually by an
> Administrator, and,
>      should be available within the same directory where the source code
> runs. */
>      if (i < 10) {_filename = "0" + Integer.toString(i);}
>      else {_filename = Integer.toString(i);}
>      String _temp = _filename;
>      _filename = _temp + ".GIF";
>      //TODO: Relative path might change when implementing?
>      _filename = System.getProperty("user.dir") + "\\img\\" + _filename;
>      _file = new File(_filename);
>      //read from an input stream
>      _is = new BufferedInputStream (new FileInputStream(_filename));
>      _image = ImageIO.read(_is);
>      if (_file.exists()) {
>      CardIcons.add(_image);
>      _log.debug(_filename + " loaded.");
>      }
>      }
>      catch (IOException e) { _log.debug(e.getMessage()); }
>      }
>     }
> private static ArrayList<Image> CardIcons = new ArrayList<Image>();
> private static ArrayList<Card> deckOfCards = new ArrayList<Card>();
> private static final Logger _log = Logger.getLogger(Poker.class);
> public static final short MAX_CARDS_IN_DECK = 52;
> public static final short MAX_SUITS_IN_DECK = 4;
> public static final short MAX_RANK_IN_DECK = 13;
> public static final short MAX_PLAYERS_PER_TABLE = 5;
> public static final short MAX_GAMES_PER_SESSION = 1; //TODO: implement
> concurrent games and UI at a later stage.
> /* References
> * ----------
> * Information about poker at http://en.wikipedia.org/wiki/Poker.
> * List of poker hands at http://en.wikipedia.org/wiki/Poker_hands.
> * Rules for Texas Hold'Em at http://en.wikipedia.org/wiki/Texas_hold_'em.
>  This will be implemented at a later stage.
> * Steve Badger, How to Play Poker at
> http://www.playwinningpoker.com/articles/how-to-play-poker.
> * Graphics to be implemented at a later stage.
> */
> }
> Player.java
> ...
> public String toString() {
> String _cardsHeld = "";
> BasicConfigurator.configure();
> //TODO: DEBUG grammatical error i.e. comma separating each card and "." for
> the last card, the last rule is not working as expected.
> for (int i = 0; i < CardsHeld.size(); i++) {_cardsHeld +=
> CardsHeld.get(i).toString() + " ";}
> return (name + " holds the following cards: " + _cardsHeld) ;
> }
> ...
> public int hashCode() {
> int _hash = 7;
> int _cpCount = this.name.codePointCount(0, name.length());
> int _codePointV = 0;
> while (_cpCount < this.name.length()) {
> _codePointV += this.name.codePointAt(_cpCount);
> _cpCount++;
> }
> _hash = _hash * 31 + _codePointV;
> return _hash;
> }
>
> Output
> [main] DEBUG poker.Poker  - Player One holds the following cards: TEN of
> HEARTS SEVEN of CLUBS .
> 172 [main] DEBUG poker.Poker  - Player One holds the following cards: TEN of
> HEARTS SEVEN of CLUBS .
> 172 [main] DEBUG poker.Poker  - 217
> 172 [main] DEBUG poker.Poker  - 217
> 172 [main] DEBUG poker.Poker  - Player Two holds the following cards: SEVEN
> of SPADES TEN of CLUBS .
> 172 [main] DEBUG poker.Poker  - Player Two holds the following cards: SEVEN
> of SPADES TEN of CLUBS .
> 172 [main] DEBUG poker.Poker  - Player Two holds the following cards: SEVEN
> of SPADES TEN of CLUBS .
> 172 [main] DEBUG poker.Poker  - 217
> 172 [main] DEBUG poker.Poker  - 217
> 172 [main] DEBUG poker.Poker  - 217
> Rgds,
> Jonathan
>
> On 24 April 2011 11:05, Christian Grobmeier <[email protected]> wrote:
>>
>> Hello Jonathan,
>>
>> this message appears when the log4j.xml|properties file could not be
>> found on your classpath.
>> Usually it should be at src/main/resources, this folder visible as
>> classpath folder on eclipse.
>>
>> However you can start your app with -Dlog4j.debug=true to spot out at
>> which locations your configuration is searched
>>
>> Your pom.xml is a maven file and should not have any impact on log4j
>> (except you need the dependency of course). Same is true for eclipse.
>> Only th elocation of your config file is important.
>>
>> Cheers
>>
>> On Sat, Apr 23, 2011 at 6:53 PM, Jonathan Camilleri
>> <[email protected]> wrote:
>> > Hi,
>> > Any idea why my logger is not logging (see Deck.java).  Error message:
>> > log4j:WARN No appenders could be found for logger (poker.Deck).
>> > log4j:WARN Please initialize the log4j system properly.
>> > log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
>> > more info.
>> > TWO of CLUBS
>> > Having, googled the issue, I tried adding pom.xml to the directory where
>> > the
>> > source code files reside.  I am using Eclipse 3.6.2, which has an
>> > intricate
>> > way of adding JARs to my project.
>> > Any ideas?
>> >
>> > --
>> > Jonathan Camilleri
>> >
>> > Mobile (MT): 00356 7982 7113
>> > E-mail: [email protected]
>> > Please consider your environmental responsibility before printing this
>> > e-mail.
>> >
>> > I usually reply to e-mails within 2 business days.  If it's urgent, give
>> > me
>> > a call.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [email protected]
>> > For additional commands, e-mail: [email protected]
>> >
>>
>>
>>
>> --
>> http://www.grobmeier.de
>
>
>
> --
> Jonathan Camilleri
>
> Mobile (MT): 00356 7982 7113
> E-mail: [email protected]
> Please consider your environmental responsibility before printing this
> e-mail.
>
> I usually reply to e-mails within 2 business days.  If it's urgent, give me
> a call.
>



-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to