Package org.dspace.app.statistics

Examples of org.dspace.app.statistics.LogLine


                // analysis, and ease of code reading too - Pending further thought
                String line = null;
                while ((line = br.readLine()) != null)
                {
                    // get the log line object
                    LogLine logLine = getLogLine(line);
                   
                    // if there are line segments get on with the analysis
                    if (logLine != null)
                    {
                        // first find out if we are constraining by date and
                        // if so apply the restrictions
                        if ((startDate != null) && (!logLine.afterDate(startDate)))
                        {
                            continue;
                        }
                       
                        if ((endDate !=null) && (!logLine.beforeDate(endDate)))
                        {
                            break;
                        }
                       
                        // count the number of lines parsed
                        lineCount++;
                       
                        // if we are not constrained by date, register the date
                        // as the start/end date if it is the earliest/latest so far
                        // FIXME: this should probably have a method of its own
                        if (startDate == null)
                        {
                            if (logStartDate != null)
                            {
                                if (logLine.beforeDate(logStartDate))
                                {
                                    logStartDate = logLine.getDate();
                                }
                            }
                            else
                            {
                                logStartDate = logLine.getDate();
                            }
                        }
                       
                        if (endDate == null)
                        {
                            if (logEndDate != null)
                            {
                                if (logLine.afterDate(logEndDate))
                                {
                                    logEndDate = logLine.getDate();
                                }
                            }
                            else
                            {
                                logEndDate = logLine.getDate();
                            }
                        }
                       
                        // count the warnings
                        if (logLine.isLevel("WARN"))
                        {
                            // FIXME: really, this ought to be some kind of level
                            // aggregator
                            warnCount++;
                        }

                        // is the action a search?
                        if (logLine.isAction("search"))
                        {
                            // get back all the valid search words from the query
                            String[] words = analyseQuery(logLine.getParams());
                           
                            // for each search word add to the aggregator or
                            // increment the aggregator's counter
                            for (int j = 0; j < words.length; j++)
                            {
                                // FIXME: perhaps aggregators ought to be objects
                                // themselves
                                searchAggregator.put(words[j], increment(searchAggregator, words[j]));
                            }
                        }

                        // is the action a login, and are we counting user logins?
                        if (logLine.isAction("login") && !userEmail.equals("off"))
                        {
                            userAggregator.put(logLine.getUser(), increment(userAggregator, logLine.getUser()));
                        }

                        // is the action an item view?
                        if (logLine.isAction("view_item"))
                        {
                            String handle = logLine.getParams();

                            // strip the handle string
                            Matcher matchHandle = handleRX.matcher(handle);
                            handle = matchHandle.replaceAll("");
                           
                            // strip the item id string
                            Matcher matchItem = itemRX.matcher(handle);
                            handle = matchItem.replaceAll("");

                            handle.trim();

                            // either add the handle to the aggregator or
                            // increment its counter
                            itemAggregator.put(handle, increment(itemAggregator, handle));
                        }

                        // log all the activity
                        actionAggregator.put(logLine.getAction(), increment(actionAggregator, logLine.getAction()));
                    }
                }

                // close the file reading buffers
                br.close();
View Full Code Here


        }
       
        if (match.matches())
        {
            // set up a new log line object
            LogLine logLine = new LogLine(parseDate(match.group(1).trim()),
                                          LogManager.unescapeLogField(match.group(2)).trim(),
                                          LogManager.unescapeLogField(match.group(3)).trim(),
                                          LogManager.unescapeLogField(match.group(4)).trim(),
                                          LogManager.unescapeLogField(match.group(5)).trim());
           
View Full Code Here

            BufferedReader input =  new BufferedReader(new FileReader(new File(in)));
            Writer output = new BufferedWriter(new FileWriter(new File(out)));

            try {
                String line;
                LogLine lline;
                String lout;
                String id;
                String handle;
                String ip;
                String date;
                DSpaceObject dso;
                String uid;
                String lastLine = "";
                while ((line = input.readLine()) != null)
                {
                    // Read inthe line and covnert it to a LogLine
                    lines++;
                    if (verbose) System.out.println("  - IN: " + line);
                    lline = LogAnalyser.getLogLine(line);

                    // Get rid of any lines that aren't INFO
                    if ((lline == null) || (!lline.isLevel("INFO")))
                    {
                        if (verbose) System.out.println("   - IGNORED!");
                        continue;
                    }

                    // Get the IP address of the user
                    Matcher matcher = ipaddrPattern.matcher(line);
                    if (matcher.find())
                    {
                        ip = matcher.group(1);
                    }
                    else
                    {
                        ip = "unknown";
                    }

                    // Get and format the date
                    // We can use lline.getDate() as this strips the time element
                    date = dateFormatOut.format(
                           dateFormatIn.parse(line.substring(0, line.indexOf(',')),
                                                 new ParsePosition(0)));

                    // Generate a UID for the log line
                    // - based on the date/time
                    uid = dateFormatOutUID.format(
                           dateFormatInUID.parse(line.substring(0, line.indexOf(' ', line.indexOf(' ') + 1)),
                                                 new ParsePosition(0)));

                    try
                    {
                        // What sort of view is it?
                        // (ignore lines from org.dspace.usage.LoggerUsageEventListener which is 1.6 code)
                        if ((lline.getAction().equals("view_bitstream")) &&
                            (!lline.getParams().contains("invalid_bitstream_id")) &&
                            (!lline.getParams().contains("withdrawn")) &&
                            ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                        {
                            id = lline.getParams().substring(13);
                        }
                        else if ((lline.getAction().equals("view_item")) &&
                                ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                        {
                            handle = lline.getParams().substring(7);
                            dso = HandleManager.resolveToObject(context, handle);
                            id = "" + dso.getID();
                        }
                        else if ((lline.getAction().equals("view_collection")) &&
                                 ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                        {
                            id = lline.getParams().substring(14);
                        }
                        else if ((lline.getAction().equals("view_community")) &&
                                 ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                        {
                            id = lline.getParams().substring(13);
                        }
                        else
                        {
                            //if (verbose) System.out.println("   - IGNORED!");
                            continue;
                        }

                        // Construct the log line
                        lout = uid + "," +
                               lline.getAction() + "," +
                               id + "," +
                               date + "," +
                               lline.getUser() + "," +
                               ip + "\n";
                    }
                    catch (Exception e)
                    {
                        if (verbose) System.out.println("  - IN: " + line);
View Full Code Here

        LogAnalyser.setRegex(in);

        // Open the file and read it line by line
        try {
            String line;
            LogLine lline;
            String lout;
            String id;
            String handle;
            String ip;
            String date;
            DSpaceObject dso;
            String uid;
            String lastLine = "";

            while ((line = input.readLine()) != null)
            {
                // Read in the line and convert it to a LogLine
                lines++;
                if (verbose)
                {
                    System.out.println("  - IN: " + line);
                }
                lline = LogAnalyser.getLogLine(line);

                // Get rid of any lines that aren't INFO
                if ((lline == null) || (!lline.isLevel("INFO")))
                {
                    if (verbose)
                    {
                        System.out.println("   - IGNORED!");
                    }
                    continue;
                }

                // Get the IP address of the user
                Matcher matcher = ipaddrPattern.matcher(line);
                if (matcher.find())
                {
                    ip = matcher.group(1);
                }
                else
                {
                    ip = "unknown";
                }

                // Get and format the date
                // We can use lline.getDate() as this strips the time element
                date = dateFormatOut.format(
                       dateFormatIn.parse(line.substring(0, line.indexOf(',')),
                                             new ParsePosition(0)));

                // Generate a UID for the log line
                // - based on the date/time
                uid = dateFormatOutUID.format(
                       dateFormatInUID.parse(line.substring(0, line.indexOf(' ', line.indexOf(' ') + 1)),
                                             new ParsePosition(0)));

                try
                {
                    // What sort of view is it?
                    // (ignore lines from org.dspace.usage.LoggerUsageEventListener which is 1.6 code)
                    if ((lline.getAction().equals("view_bitstream")) &&
                        (!lline.getParams().contains("invalid_bitstream_id")) &&
                        (!lline.getParams().contains("withdrawn")) &&
                        ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                    {
                        id = lline.getParams().substring(13);
                    }
                    else if ((lline.getAction().equals("view_item")) &&
                            ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                    {
                        handle = lline.getParams().substring(7);
                        dso = HandleManager.resolveToObject(context, handle);
                        id = "" + dso.getID();
                    }
                    else if ((lline.getAction().equals("view_collection")) &&
                             ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                    {
                        id = lline.getParams().substring(14);
                    }
                    else if ((lline.getAction().equals("view_community")) &&
                             ((!line.contains("org.dspace.usage.LoggerUsageEventListener")) || newEvents))
                    {
                        id = lline.getParams().substring(13);
                    }
                    else
                    {
                        //if (verbose) System.out.println("   - IGNORED!");
                        continue;
                    }

                    // Construct the log line
                    lout = uid + "," +
                           lline.getAction() + "," +
                           id + "," +
                           date + "," +
                           lline.getUser() + "," +
                           ip + "\n";
                }
                catch (Exception e)
                {
                    if (verbose)
View Full Code Here

TOP

Related Classes of org.dspace.app.statistics.LogLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.