0

I have such log4j.properties file:

#Wed Jan 18 12:55:30 EET 2017
log4j.rootLogger=ERROR, stdout, gui, clientFile
log4j.logger.app=DEBUG
...

And when I start my application first line with timestamp (#Wed Jan 18 12:55:30 EET 2017) is always changing. It causes some problems with Git commits (I can not add this file to .gitignore).

Found what is adding the timestamp: this method is calling in app linkedProperties.store(fileOutputStream, null); The implementation of store() method is from java.util.Properties.

    package java.util;
    ...
    public class Properties extends Hashtable<Object,Object> {
    ...

    public void store(OutputStream out, String comments)
        throws IOException
    {
        store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
               comments,
               true);
    }

    private void store0(BufferedWriter bw, String comments, boolean escUnicode)
            throws IOException
        {
            if (comments != null) {
                writeComments(bw, comments);
             }
            bw.write("#" + new Date().toString());
            bw.newLine();
            synchronized (this) {
                for (Enumeration<?> e = keys(); e.hasMoreElements();) {
                    String key = (String)e.nextElement();
                    String val = (String)get(key);
                    key = saveConvert(key, true, escUnicode);
                    /* No need to escape embedded and trailing spaces for value, hence
                     * pass false to flag.
                     */
                    val = saveConvert(val, false, escUnicode);
                    bw.write(key + "=" + val);
                    bw.newLine();
                }
            }
            bw.flush();
        }
    ...

How can I avoid this bw.write("#" + new Date().toString());? Is there something similar to java.util.Properties?

Maksym
  • 2,650
  • 3
  • 32
  • 50
  • Why can't this file be added to the gitignore? – Tom Jan 18 '17 at 13:52
  • Because your configuration inside your Eclipse IDE. A simple solution, download a new Eclipse IDE, then import your source code into. – Vy Do Jan 18 '17 at 14:33
  • @thebluefox I can add it, but file can be changed by someone. And I need to see this changes on git. So .gtiignore is not the best way to solve this issue. – Maksym Jan 18 '17 at 14:39

2 Answers2

1

Edit: This answer is now laregely redundant given the OP's edits, following my suggestion to find what was adding the timestamp to the file. However I'll keep it here as it may help someone, perhaps.


Firstly, it's not really possible to instruct Git to ignore individual lines in a file.

My first recommendation would be to find what is adding the timestamp to the file and stop it.

The only thing that comes to mind that could help you in Git specifically is removing the file from Gits working tree.

git update-index --skip-worktree <file>

This will instruct Git that a changed version of this file shouldn't be committed and so will not include it in its working tree, but will still keep the tracked copy in the repository. Look here for official docs

Obivously, this won't work if you require developers to regularly update/commit this file.

Tom
  • 4,257
  • 6
  • 33
  • 49
  • Thanks, my question just dublicates this one http://stackoverflow.com/questions/6184335/properties-store-suppress-timestamp-comment – Maksym Jan 18 '17 at 15:39
  • It's amazing what you find when you ask/search for the right question – Tom Jan 18 '17 at 15:40
0

I have just overrided public void store(OutputStream out, String comments) (removed bw.write("#" + new Date().toString())). For more information about this problem you can use this link (it fully dublicates my issue): Properties.store() - suppress timestamp comment .

Community
  • 1
  • 1
Maksym
  • 2,650
  • 3
  • 32
  • 50