RE: wm.log time stamp broken?

"Mike Weerdenburg - de Bruin (Werk)" <[email protected]> Fri, 31 Mar 2006 11:11:51 +0200
Newsgroups gmane.comp.java.webmacro.user
Message-ID <200603311118736.SM03016@schuurpcxp>
This is a multi-part message in MIME format.

------=_NextPart_000_0022_01C654B3.E9C9E640
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello Marcel,

I had a look at my logfile... and I have the same problem!

It looks like it logs with the latest startup time!

These logs are from today... but the timestamp is from yesterday!
30-03-2006 14:47:43.812
30-03-2006 14:47:43.812
30-03-2006 14:47:43.812
... Etc. etc.


I have done some quick testing:

It seems like Clock.java doesn't return the correct value's.
In particular: System.currentTimeMillis()

System.out:
------------
System.currentTimeMillis() 1143795904156
time 1143795904156
TIME 1143795880312
TIME - time -23844
< 1000

System.currentTimeMillis() 1143795904156
time 1143795904156
TIME 1143795880312
TIME - time -23844
< 1000

System.currentTimeMillis() 1143795904156
time 1143795904156
TIME 1143795880312
TIME - time -23844
< 1000
... Etc. etc.

I don't have the time to sort this problem out...
But I hope it helps someone else to solve this problem!

Greetings,
Mike

Atatchments:
LogFile.java	(Latest version! With LogFilePerDay etc.)
Clock.java		(With some System.out.println's for debugging)


-----Oorspronkelijk bericht-----
Van: [email protected]
[mailto:[email protected]] Namens Marcello H
Verzonden: vrijdag 31 maart 2006 10:14
Aan: [email protected]
Onderwerp: ***SPAM***[WebMacro-user] wm.log time stamp broken?

I checked out the cvs-code this week, and found out that the time stamp
in the wm-file is almost the same on ervy hit from the same logger.

(I must say, i didn't look at this particular thing in detail lately...)

Do other people experience this also?

Greetings,
Marcel Huijkman


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting =
language
that extends applications into web and mobile media. Attend the live =
webcast
and join the prime developer group breaking into this new coding =
territory!
http://sel.as-us.falkag.net/sel?cmd=3Dk&kid=110944&bid$1720&dat=121642
_______________________________________________
Webmacro-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/webmacro-user

------=_NextPart_000_0022_01C654B3.E9C9E640
Content-Type: application/octet-stream;
	name="LogFile.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="LogFile.java"

/*
 * Copyright (C) 1998-2005 Semiotek Inc.  All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted under the terms of either of the =
following
 * Open Source licenses:
 *
 * The GNU General Public License, version 2, or any later version, as
 * published by the Free Software Foundation
 * (http://www.fsf.org/copyleft/gpl.html);
 *
 *  or
 *
 * The Semiotek Public License (http://webmacro.org/LICENSE.)
 *
 * This software is provided "as is", with NO WARRANTY, not even the
 * implied warranties of fitness to purpose, or merchantability. You
 * assume all risks and liabilities associated with its use.
 *
 * See www.webmacro.org for more information on the WebMacro project.
 *
 * @author Mike Weerdenburg
 * @author Marcel Huijkman
 *
 * @version	12-12-2005
 *
 */

/*
	ChangeLog:

	12-12-2005 (Mike Weerdenburg)
		LogFilePerDay
		It was :
			exampl. c:/logs/wm.log -> c:/logs/wm.log_20050105
			exampl. c:/logs/wmlog -> c:/logs/wm_log_20050105

		Now it is :
			exampl. c:/logs/wm.log -> c:/logs/wm_20050105.log
			exampl. c:/logs/wmlog -> c:/logs/wm_log_20050105

		And write a message to the 'old' logfile when switching to a 'new' =
one.

	17-07-2002 (Marcel Huijkman)
		setting for WebMacro.properties added

		LogFilePerDay
		usage:
			LogFilePerDay=3DFALSE or TRUE

		LogFileAutoFlush
		usage:
			LogFileAutoFlush=3DFALSE or TRUE

		(Notice: Only handy when developing on a Operating system, that =
buffers file-writing,
		not recommended for production, since it obviously slows down the =
machine.)
*/


package org.webmacro.util;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class LogFile extends AbstractLogFile
{

    private PrintStream _out;
    private boolean _logFilePerDay =3D false;
    private boolean _logFileAutoFlush =3D false;
    private String _prevLogDate =3D "";
    private String _actLogDate =3D "";
    private SimpleDateFormat _logFileSuffix =3D new =
SimpleDateFormat("_yyyyMMdd");
    private String _orgLogFile =3D "";

    /**
     * Create a new LogFile instance.
     */
    public LogFile (Settings s) throws FileNotFoundException
    {
        super(s);
        init(s.getSetting("LogFile"));

        String strLogFilePerDay =3D s.getSetting("LogFilePerDay");

        if (strLogFilePerDay !=3D null)
        {
            if (strLogFilePerDay.equalsIgnoreCase("TRUE"))
            {
                _logFilePerDay =3D true;
            }
        }
        String strLogFileAutoFlush =3D s.getSetting("LogFileAutoFlush");
        if (strLogFileAutoFlush !=3D null)
        {
            if (strLogFileAutoFlush.equalsIgnoreCase("TRUE"))
            {
                _logFileAutoFlush =3D true;
            }
        }
    }

    public LogFile (String fileName) throws FileNotFoundException
    {
        init(fileName);
    }

    private void init (String fileName) throws FileNotFoundException
    {
        if ((fileName =3D=3D null)
                || (fileName.equalsIgnoreCase("system.err")
                || fileName.equalsIgnoreCase("none")
                || fileName.equalsIgnoreCase("stderr")))
        {
            _out =3D System.err;
            _name =3D "System.err";
        }
        else
        {
            if (_logFilePerDay)
            {
                // change logfilename if a logfile per day is wanted
                _orgLogFile =3D fileName;
                _actLogDate =3D =
_logFileSuffix.format(Calendar.getInstance().getTime());
                _prevLogDate =3D _actLogDate;

                // Find the last . in the filename.
                int intLastDot =3D fileName.lastIndexOf('.');
                if (intLastDot !=3D -1)
                {
                    // fileName has a suffix: place the date between =
prefix and suffix.
                    // This way your favourite log-viewer stil =
recognizes the logfile.
                    // exampl. c:/logs/wm.log -> c:/logs/wm_20050105.log
                    fileName =3D fileName.substring(0,intLastDot) + =
_actLogDate + fileName.substring(intLastDot);
                }
                else
                {
                    // fileName has no suffix: place the date after the =
fileName.
                    // exampl. c:/logs/wmlog -> c:/logs/wm_log_20050105
                    fileName =3D fileName + _actLogDate;
                }

                // Write a message to the 'old' logfile when switching =
to a 'new' one.
                Object[] _args =3D {Clock.getDate(), "LogFile", =
"NOTICE", "Switching to logfile : " + fileName};
                _out.println(_mf.format(_args));

                // close the 'old' logfile.
                _out.close();
            }

            _name =3D fileName;
            _out =3D new PrintStream(new BufferedOutputStream( new =
FileOutputStream(fileName, true)));

            if (_orgLogFile.length() =3D=3D 0)
            {
                _orgLogFile =3D fileName;
            }
        }
        if (_defaultLevel <=3D LogSystem.NOTICE)
        {
            log(Clock.getDate(), "LogFile", "NOTICE", "--- Log Started =
---", null);
        }
    }

    /**
     * Create a new LogFile instance
     */
    public LogFile (PrintStream out)
    {
        _out =3D out;
        _name =3D out.toString();
    }

    public void log (Date date, String name, String level, String =
message, Throwable e)
    {
        if (_logFilePerDay)
        {
            _actLogDate =3D =
_logFileSuffix.format(Calendar.getInstance().getTime());
            if (!_actLogDate.equals(_prevLogDate))
            {
                try
                {
                    init(_orgLogFile);
                }
                catch (FileNotFoundException f_ex)
                {
                    System.err.println("Logfile " + _name + " not =
found!");
                }
            }
        }

        Object[] _args =3D {date, name, level, message};
        _out.println(_mf.format(_args));
        if (_trace && (e !=3D null))
        {
            e.printStackTrace(_out);
        }

        if (_logFileAutoFlush)
        {
            flush();
        }
    }

    public void flush ()
    {
        _out.flush();
    }

}
------=_NextPart_000_0022_01C654B3.E9C9E640
Content-Type: application/octet-stream;
	name="Clock.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Clock.java"

/*
 * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted under the terms of either of the =
following
 * Open Source licenses:
 *
 * The GNU General Public License, version 2, or any later version, as
 * published by the Free Software Foundation
 * (http://www.fsf.org/copyleft/gpl.html);
 *
 *  or
 *
 * The Semiotek Public License (http://webmacro.org/LICENSE.)
 *
 * This software is provided "as is", with NO WARRANTY, not even the
 * implied warranties of fitness to purpose, or merchantability. You
 * assume all risks and liabilities associated with its use.
 *
 * See www.webmacro.org for more information on the WebMacro project.
 */


package org.webmacro.util;

import java.util.Date;

/**
 * This is an optimization. "System.currentTimeMillis()" is a relatively
 * slow method, and "new Date()" is an incredibly expensive operation.
 * Update: System.ctm is no longer all that slow; replaced with a =
version
 * that caches the Date but not the time.
 */
final public class Clock
{

    /**
     * Every tick interval the following variable is updated with the =
current system time
     */
    static public long TIME =3D System.currentTimeMillis();

    /**
     * Date information
     */
    private static Date date =3D new Date();

    /**
     * The current date. This object is updated not faster than once per =
second.
     */
    public synchronized static Date getDate ()
    {

        long time =3D System.currentTimeMillis();

    // Debug info - start
    System.out.println();
    System.out.println("System.currentTimeMillis() " + =
System.currentTimeMillis());
    System.out.println("time " + time);
    System.out.println("TIME " + TIME);
    System.out.println("TIME - time " + (TIME - time));
    // Debug info - end

        if ((TIME - time) > 1000) {
            TIME =3D time;
            date =3D new Date(TIME);

    // Debug info - start
    System.out.println("> 1000");
    // Debug info - end

        }

    // Debug info - start
    else
    {
        System.out.println("< 1000");
    }
    // Debug info - end
        return date;
    }

}



------=_NextPart_000_0022_01C654B3.E9C9E640--




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642