Logging to a file without using Logger?

Hi all,
I've been thinking of adding logging support to my app. So I found the Logger class. It seems to be ok, but that is not exactly what i was looking for.
What I want to implement is cyclic/rolling log. But I am not talking about cycling files (the Logger class works fine with that), I am talking about cycling lines in only one log file. I mean, to add a limit to the file (let's suppose it is a line count limit, but it can be implemented as a file size limit too) and once this line limit is reached the next log would erase the oldest line in the log file and move the rest to the place where their previous line had been (just like erasing the first element in an array and moving the rest of the elements one place back). Finally the new line is added at the end log.
I found the Logger class useful because a limit can be set to a log file. However when the file reaches the limit and a new log is being written ALL previous log entries are erased... unnecessary loosing a lot of useful data.
I also took a look at [Log4j|http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/package-summary.html] but they don't seem to have what I am looking for.
Is there any library or any other class I've missed to perform this?
In case there isn't, what could be the best way to implement it? An ArrayList<String>?
Thanks for your time :)

asdasdasdasdasdasdasdasd wrote:
What I want to implement is cyclic/rolling log. But I am not talking about cycling files (the Logger class works fine with that), I am talking about cycling lines in only one log file. I mean, to add a limit to the file (let's suppose it is a line count limit, but it can be implemented as a file size limit too) and once this line limit is reached the next log would erase the oldest line in the log file and move the rest to the place where their previous line had been (just like erasing the first element in an array and moving the rest of the elements one place back). Finally the new line is added at the end log.That's a bad idea. Once you hit the limit, you'll be rewriting the entire log file for every log message. Why would you want to do that?

Similar Messages

  • How to open a text file without using dialog box

    I can open a file using dialog box but I want to open a file without using any dialog box for writing.
    With the following commands a new file is created.
    File outputFile = new File("outagain.txt");
    FileWriter out = new FileWriter(outputFile);
    I want to open an existing file and put some more text in it using FileWriter or any other object
    rgds,
    Arsalan

    import java.io.*;
    class UReader
        BufferedReader in;
        BufferedReader input;
        String fileName;
        public UReader(String fileName)
            this.fileName = null;
            this.fileName = fileName;
            try
                in = new BufferedReader(new FileReader(fileName));
                input = new BufferedReader(new FileReader("A.b"));
            catch(IOException _ex) { }
        public final String getContent()
            String txt = "";
            try
                while(in.ready())
                    txt = txt + in.readLine();
                    txt = txt + "\n";
                in.close();
                txt.trim();
            catch(IOException _ex) { }
            return txt;
        public final String getLine(int row)
            try
                input = new BufferedReader(new FileReader(fileName));
            catch(IOException _ex) { }
            String txt = null;
            if(row <= getRows()) {
                try
                    for(int i = 0; i < row; i++)
                        txt = input.readLine();
                    input.close();
                catch(IOException _ex) { }
            } else {
                txt = "Index out of Bounds";
            return txt;
        public final int getRows()
            try
                input = new BufferedReader(new FileReader(fileName));
            catch(IOException _ex) { }
            String txt = null;
            int rows = 0;
            try
                while(input.ready())
                    txt = input.readLine();
                    rows++;
                input.close();
            catch(IOException _ex) { }
            return rows;
    import java.io.*;
    import java.util.*;
    class UWriter
        PrintWriter out;
        String fileName;
        String[] txt;
        static int NEW_LINE = 1;
        static int APPEND = 0;
        public UWriter(String s)
            fileName = null;
            txt = null;
            fileName = s;
            try
                out = new PrintWriter(new BufferedWriter(new FileWriter(s, true)));
            catch(IOException ioexception) { }
        public final void addContent(String s, int i)
            int l = 0;
            StringBuffer sb = new StringBuffer(s);
            s.replaceAll("\n\n", "\n###\n");
            StringTokenizer str = new StringTokenizer(s, "\n");
            String token = null;
            while (str.hasMoreTokens()) {
                ++l;
                token = str.nextToken();
            str = new StringTokenizer(s, "\n");
            txt = new String[l];
            int k = 0;
            String test;
            while (str.hasMoreTokens()) {
                test = str.nextToken();
                if (test.equals("###")) test = "";
                txt[k++] = test;
            if(i == 0) {
                try
                    for (int j = 0; j < txt.length; ++j) {
                        out.println(txt[j]);
                    out.close();
                catch(Exception ioexception) { }
            } else {
                try
                    out.println();
                    for (int j = 0; j < txt.length; ++j) {
                        out.println(txt[j]);
                    out.close();
                catch(Exception ioexception1) { }
        public final void writeContent(String s)
            int l = 0;
            s.replaceAll("\n\n", "###");
            StringTokenizer str = new StringTokenizer(s, "\n");
            String token = null;
            while (str.hasMoreTokens()) {
                ++l;
                token = str.nextToken();
            str = new StringTokenizer(s, "\n");
            txt = new String[l];
            int k = 0;
            String test;
            while (str.hasMoreTokens()) {
                test = str.nextToken();
                if (test.equals("###")) test = "";
                txt[k++] = test;
            try
                PrintWriter bufferedwriter = new PrintWriter(new BufferedWriter(new FileWriter(fileName, false)));
                for (int j = 0; j < txt.length; ++j) {
                    bufferedwriter.println(txt[j]);
                bufferedwriter.close();
            catch(IOException ioexception) { }
    }Maybe they are not the best codes, i wrote them a long time ago, so dont ask why i did anything wierd. :D
    But anyway it works.

  • Regarding reading the data from the files without using Stremas

    hai to all of u...
    here i have a problem where i have to read the data from the files without using any streams.
    please guide me how to do this one,if possible by giving with an example
    Thanks & Regard
    M.Ramakrishna

    Simply put, you can't.
    By why do you need to?

  • Export table data in a flat file without using FL

    Hi,
    I am looking for options where I can export table data into a flat file without using FL(File Layout) i.e., by using App Engine only.
    Please share your experience if you did anything as this
    Thanks

    A simple way to export any record (table/view) to an csv fiel, is to create a rowset and loop through all record fields, like below example code
    Local Rowset &RS;
    Local Record &Rec;
    Local File &MYFILE;
    Local string &FileName, &strRecName, &Line, &Seperator, &Value;
    Local number &numRow, &numField;
    &FileName = "c:\temp\test.csv";
    &strRecName = "PSOPRDEFN";
    &Seperator = ";";
    &RS = CreateRowset(@("Record." | &strRecName));
    &RS.Fill();
    &MYFILE = GetFile(&FileName, "W", %FilePath_Absolute);
    If &MYFILE.IsOpen Then
       For &numRow = 1 To &RS.ActiveRowCount
          &Rec = &RS(&numRow).GetRecord(@("RECORD." | &strRecName));
          For &numField = 1 To &Rec.FieldCount
             &Value = String(&Rec.GetField(&numField).Value);
             If &numField = 1 Then
                &Line = &Value;
             Else
                &Line = &Line | &Seperator | &Value;
             End-If;
          End-For;
          &MYFILE.WriteLine(&Line);
       End-For;
    End-If;
    &MYFILE.Close(); You can of course create an application class for generic calling this piece of code.
    Hope it helps.
    Note:
    Do not come complaining to me on performance issues ;)

  • Upload file without using file upload UI Element

    Hi all.
    I need upload a .txt file without using file upload UI Element because filename is not insert by user. The filename is generated by program. I try to use 'GUI_UPLOAD' and 'WS_UPLOAD' but don't work.
    Many thanks in advance.

    As you correctly pointed out we cannot use the gui_upload and gui_download fm's in webdynpro because they require sap gui and WD Components generally run in a HTML or Portal environment.
    The only option available is File Upload Element

  • Saving a Text data to a PDF file without using print option

    Hi,
    I want to save a Text to a PDF file. I want to assign the path of the PDF file as a default one.
    If I use Print options, then it ask for the file path at the run time.
    Is there any method to save to a PDF file without using print option in Labview 8.2.
    Regards,
    Raja

    This question comes up a lot. Did you try searching? It depends on the PDF printer driver that you're using. See here, here, here, ...

  • Embed flash file without using IFrame UI

    Hi all,
    Can any one tell me how i can embed flash file without using IFrame UI ?

    Hi
    To run a flash file you will definetely need a platform for which you need a shockwave player or a simple browser window. From webdynpro, the purpose of making it run through a IFrame is at runtime, the frame acts as a window for the flash file to run. Hence its the direct option of running it. Otherwise, you need to use a external window to invoke it seperetely in a browser window to run the file.
    If you have any specific issues, do let us know, or else its the best option @!
    thanks
    sathya

  • Embed  html file without using IFrame UI

    Is there any way to embed html file without using IFrame UI?

    Hi
    To embed a static HTML content inside your view, Iframe is the easiest form or else, you can provide links through Linktourl UI or through a static text or a button, invoke a action and display the HTML content inside the frame or call it in a seperate (external) window.
    Otherwise, we have only less options!
    if you have anything specific, do let us know
    thanks
    sathya

  • Urgent : How to upload a tif file without using upload element

    could someone please tell me how to upload a tif file(any file) without using upload element. Function Module GUI_UPLOAD does not work. Please suggest. Appreciate your suggestions.

    Hello Suri,
    there's currently no way to achieve this.
    Best regards,
    Thomas

  • I am wondering if there is a way to validate XML file without using .......

    I am wondering if there is a way to validate XML file without using the <!DOCTYPE... but pass in the location of the schema/DTD file as a parameter to a validating method?
    thanks

    None that I know of. The only thing close is to use the EntityResolver interface where you can modify the location of the DTD file before it's being loaded and parsed, but that requires a <!DOCTYPE ...> in the XML file.
    Good luck.

  • Is it possible to create .ncd file without using MAX?

    Is it possible to create .ncd file without using MAX? I am trying to read the data given by hundreds of possible Arb. IDs on one of the CAN port without having to create it from the MAX.
    Thank you

    Hi,
    the NI-CAN driver software does not provide functions/VIs to generate
    *.ncd files. However the *.ncd file format is just plain XML (ASCII text). Take a
    look at the example.ncd file that gets installed with NI-CAN
    (<ProgramFiles>\National Instruments\NI-CAN\):
    <?xml version="1.0" encoding="UTF-8"?>
    <nican_config version="0.1">
    <saved>8/8/2005,17:58</saved>
    <message name="TransmissionFluids">
      <id extended="0">82</id>
      <dbc>C:\Program Files\National Instruments\NI-CAN\example.ncd</dbc>
      <conflicts>0</conflicts>
      <bytes>6</bytes>
      <interface>1</interface>
      <comment></comment>
      <channel name="ClutchPressure">
        <conflicts>0</conflicts>
        <bitfield start="0" bits="8" order="0" type="1"/>
        <linear_scaling factor="1.600000e+001"
    offset="0.000000e+000" max="4.000000e+003" min="0.000000e+000"
    default="0.000000e+000" unit="kPa"/>
        <comment></comment>
      </channel>
    </message>
    </nican_config>
    Thus, you could generate *.ncd files with simple file I/O. Having XML-specific file I/O functions simplifies this task.
    -B2k

  • Can I access time capsule file without using imac

    can I access time capsule file without using imac

    From a time machine backup? No. If you mean just a regular file stored on there? Not directly. There are a couple of apps out there where you can indirectly get to a file but it's a pain. If you have need of accessing a file both from the mac and the iPad then I suggest DropBox. You get 2GB free and it's a good way to share information between machines and devices.

  • Best way to transfer files without using migration assistant

    upgrading from snow leopard to mavericks goes ok, but migrating files hangs with "less than a minute to go". What is the best way to transfer user files without using migration assistant?

    I keep backups of essential documents in Dropbox, and then the files can sync when I reinstall Dropbox.
    For larger collections of files, for example, my Documents folder, or iTunes or iPhoto libraries, I transfer them from a Time Machine Backup- just by going into the backup manually and restoring the folders.
    If you have files that can fit on a flash drive, then you can use that, which is very fast.

  • How to get the update file without using Nokia Sof...

    The network connection is unreliable and downloading the firmware update using PC Suite for my Nokia E90 proves difficult. Does anyone know how I can get the firmware version 300.34.84?
    The trouble is Nokia's Software Updater does not accommodate any slight interruption to the connection during the update process. I will update this discussion with what version of PC Suite I have once I get that info.
    Any help is kindly appreciated

    In fact, it is not Possible to get the update file without using Nokia Software Updater or you should search the net to find the update files in another place and even you get them, you can not use them with NSU.
    You can Update your Device with:
    1 - NSU (Nokia Software Update)
    2 - FOTA (Firmware Over The Air) for FP2 devices ONLY.
    3 - Nokia Care Center
    there is not other way to upgrade.
    Hope useful for u.
    regards
    Nokia N79 4GB
    SW Version: 32.001 RM-348 MEA

  • Opening JPG or PNG files without using PS

    I want to open simple JPG's without using PS CC.   Previously, I could open JPG's or png files with Apple's Preview; I would like to return to the simple and quick tool of using Preview.
    I have looked and can not seem to find a way to open my JPG or PNG files without using Photoshop.   Can you point me the way to accomplish this?
    Thanks,   Bob

    Joe,
    First, allow me to thank you for your reply.
    Allow me to also explain that I am handicapped and have suffered the effects of five strokes in recent years and then ask for some more help from you.
    When open any JPG image (or png, I think), it automatically opens in Photoshop CC (I also own PS 6).  This is not the desired effect, as I would like to just see the images using Preview, which is the way it used to work (before I acquired the CC application, I believe).
    I quickly tried to open an image using Preview (a PNG screen shot as you suggested), though I at a loss to use 'get info' command as you suggested, nor am I able to see the 'open with' from the drop-down in Preview.  So I have to ask you for more instructions if you can assist me further?
    I live in the Seattle area, if you can call me (I am always at home) at *removed for privacy*.  If you could call me that would be great.  With my impaired communications, I usually can understand verbal information better.
    Thanks again for getting back to me.
    Bob LaBouy

Maybe you are looking for

  • Can't remove event listener from Image

    I'm clearly missing something and would appreciate some help.  I'm trying to run an event handler when an Image completes loading,  then remove the handler so that it won't  run again should the image be reloaded later. The problem that I'm having is

  • Indesign CS5.5 can't select objects, they don't show in layers panel either

    I received an .indd file from a client. There are certain objects that I can't select. I know they aren't locked because I can't select "Unlock all on spread." The weird thing is, the objects don't show up in the layer panel. If I uncheck the layer's

  • Question in photoshop

    I created a new brush  in photoshop and I cant change the hardness of the new brush what is the solution

  • Fixed Assets - Capitalised interest

    Hello Is it possible to post manual Capitalised Interest to a specific Book of an asset. This posting should only post to the non-leading ledger. I see SAP can calculate and post capitalised interest when the depreciation has been posted but want to

  • Variable Source Datastore

    Hi all, We have 3 interfaces where we perform a join between two tables. One of the tables is common to the three interfaces and the other tables are different for the 3 interfaces but have the same columns (only the name is different). Would it poss