EzDevInfo.com

log-files interview questions

Top log-files frequently asked interview questions

Is writing server log files to a database a good idea?

After reading an article about the subject from O'Reilly, I wanted to ask Stack Overflow for their thoughts on the matter.


Source: (StackOverflow)

Best practice in choosing the drives for data and log files while installing sql server in prod environment?

I need to install a SQL server for prod environment. There are only two drives in the system one drive with 120 GB and another with 50 GB. How to choose the drives to keep the user defined db data and log files and temp db files.


Source: (StackOverflow)

Advertisements

What is the proper way to create an apache-style log file using Erlang?

I think there is a specific module for this but can no longer figure out where I saw it ...


Source: (StackOverflow)

Merging multiple log files by date including multilines

I have several logs containing lines all starting with a timestamp, so that the following works as expected to merge them:

cat myLog1.txt myLog2.txt | sort -n > combined.txt

Problem is, that myLog2.txt can also contain lines without a timestamp (e.g. java stack traces). Is there an easy way without any custom scripts to still merge them and preserve the multiline content?

Example myLog1.txt

11:48:18.825 [main] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
11:48:55.784 [main] INFO  o.h.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema

Example myLog2.txt

11:48:35.377 [qtp1484319352-19] ERROR c.w.b.c.ControllerErrorHandler -
org.springframework.beans.TypeMismatchException: Failed to convert value of type   'java.lang.String' to required type 'org.joda.time.LocalDate'; nested exception is    org.springframework.core.convert.ConversionFailedException: Failed to convert from type     java.lang.String to type @org.springframework.web.bind.annotation.RequestParam   @org.springframework.format.annotation.DateTimeFormat org.joda.time.LocalDate for value    '[2013-03-26]'; nested exception is java.lang.IllegalArgumentException: Invalid format: "    [2013-03-26]"
    at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:68) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:45) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:595) ~[spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:98) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) ~[spring-web-3.2.1.RELEAS

Expected output

11:48:18.825 [main] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
11:48:35.377 [qtp1484319352-19] ERROR c.w.b.c.ControllerErrorHandler -
org.springframework.beans.TypeMismatchException: Failed to convert value of type   'java.lang.String' to required type 'org.joda.time.LocalDate'; nested exception is    org.springframework.core.convert.ConversionFailedException: Failed to convert from type     java.lang.String to type @org.springframework.web.bind.annotation.RequestParam   @org.springframework.format.annotation.DateTimeFormat org.joda.time.LocalDate for value    '[2013-03-26]'; nested exception is java.lang.IllegalArgumentException: Invalid format: "    [2013-03-26]"
    at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:68) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:45) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:595) ~[spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:98) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) ~[spring-web-3.2.1.RELEAS
11:48:55.784 [main] INFO  o.h.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema

Thanks Marco


Source: (StackOverflow)

where is log file in nodejs app with winston

I can not find in my app directory where is 'test.log' file?

below code is in server.js

var winston = require('winston'), mylogger = new (winston.Logger)({
  transports: [
    new (winston.transports.Console) (),
    new (winston.transports.File) ({filename: 'test.log'})
  ]
});

mylogger.log('Hello world');

my app directory:

/
  app/
  config/
  public/
  server.js

Source: (StackOverflow)

How to parse log file using python and store data in database?

I am trying to parse a log file .which contains the structure like given below i want to do it with python and want to store extracted data in database how can i do this ?

i am able to parse simple key value pair but facing some problem.

1: How can i parse nested structure for example context field in the sample file is nested in main group?

2: How to tackle with condition if separator comes as a string . like for key:value pair separator is colon (:) and in the "site" key there is a key:value pair site_url:http://something.com here url also contains colon (:) which gives the wrong answer.

{
        "username": "lavania",
        "host": "10.105.22.32",
        "event_source": "server",
        "event_type": "/courses/XYZ/CS101/2014_T1/xblock
/i4x:;_;_XYZ;_CS101;_video;_d333fa637a074b41996dc2fd5e675818/handler/xmodule_handler/save_user_state",
        "context": {
            "course_id": "XYZ/CS101/2014_T1",
            "course_user_tags": {},
            "user_id": 42,
            "org_id": "XYZ"
        },
        "time": "2014-06-20T05:49:10.468638+00:00",
        "site":"http://something.com",
        "ip": "127.0.0.1",
        "event": "{\"POST\": {\"saved_video_position\": [\"00:02:10\"]}, \"GET\": {}}",
        "agent": "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0",
        "page": null
    }

    {
        "username": "rihana",
        "host": "10.105.22.32",
        "event_source": "server",
        "event_type": "problem_check",
        "context": {
            "course_id": "XYZ/CS101/2014_T1",
            "course_user_tags": {},
            "user_id": 40,
            "org_id": "XYZ",
            "module": {
                "display_name": ""
            }
        },
        "time": "2014-06-20T06:43:52.716455+00:00",
        "ip": "127.0.0.1",
        "event": {
            "submission": {
                "i4x-XYZ-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1": {
                    "input_type": "choicegroup",
                    "question": "",
                    "response_type": "multiplechoiceresponse",
                    "answer": "MenuInflater.inflate()",
                    "variant": "",
                    "correct": true
                }
            },
            "success": "correct",
            "grade": 1,
            "correct_map": {
                "i4x-XYZ-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1": {
                    "hint": "",
                    "hintmode": null,
                    "correctness": "correct",
                    "npoints": null,
                    "msg": "",
                    "queuestate": null
                }
            },
            "state": {
                "student_answers": {},
                "seed": 1,
                "done": null,
                "correct_map": {},
                "input_state": {
                    "i4x-XYZ-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1": {}
                }
            },
            "answers": {
                "i4x-XYZ-CS101-problem-33e4aac93dc84f368c93b1d08fa984fc_2_1": "choice_0"
            },
            "attempts": 1,
            "max_grade": 1,
            "problem_id": "i4x://XYZ/CS101/problem/33e4aac93dc84f368c93b1d08fa984fc"
        },
        "agent": "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:29.0) Gecko/20100101 Firefox/29.0",
        "page": "x_module"
    }


    {
        "username": "troysa",
        "host": "localhost",
        "event_source": "server",
        "event_type": "/courses/XYZ/CS101/2014_T1/instructor_dashboard/api/list_instructor_tasks",
        "context": {
            "course_id": "XYZ/CS101/2014_T1",
            "course_user_tags": {},
            "user_id": 6,
            "org_id": "XYZ"
        },
        "time": "2014-06-20T05:49:26.780244+00:00",
        "ip": "127.0.0.1",
        "event": "{\"POST\": {}, \"GET\": {}}",
        "agent": "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:29.0) Gecko/20100101 Firefox/29.0",
        "page": null
    }

Source: (StackOverflow)

unknown log files IIS creates

I have a question:

I'm working on a project in C # that creates log files in my local computer creates the necessary files and writes perfectly.

Trace.Listeners.Add(new TextWriterTraceListener("mylog.log"), "myListener"));
Trace.TraceInformation( "test message");
Trace.Flush();

But in my server also creates other files with unknown names like this:

62735167-1d87-4521-a1f2-40504fb51b59mylog.log

and contains the following lines I write. I can not delete that file. Any solution for this problem?

thanks


Source: (StackOverflow)

Sql Server change data and log path of existing database

I am having a SQL Server 2008 installation with almost 15 databases running on it. Now due to scarcity of space I would like to move the data path to another drive. What is the best practice for this. Please explain in details if including any SQL commands as I'm relatively new to SQL Server administration.

Note - I have already changed the path in SQL server properties from SQL Management Studio 2008, to the new path. But I would also like the existing databases to reside in the new path.


Source: (StackOverflow)

How to store infromation? Database vs Data-Structure vs Log files [closed]

Recently I came across a secnerio in a question :

There are n websites with n pages each and n users visiting the sites....each visit of the user has to be saved and the pages he/she has visited ( not mentioned whether in database or log files, so its upto the developer )

I decided to go on with it and do something in datastructures but a when discussed this thing with a friend of mine, he said, we can save it in database and this logically sounded correct too.

So we have 3 ways of storing anything in general...log files data-structure database

Now i am really confused, when should one go with data-structures, databases or simply log files, not only for this particular scenario but in a generic way???

Whats the real difference??


I understand that this question is primarily opinion based but couldn't get a concrete result while browsing!!


Source: (StackOverflow)

How to process a apache log file with hadoop using python

I am very newbie to hadoop and unable to understand the concept well, I had followed below process

  1. Installed Hadoop by seeing here

  2. Tried the basic examples in tutorial by seeing here and worcount example in python and working fine with them.

Actually what i am trying to do/the requirement i got is processing an apache log files in fedora(linux) located at /var/log/httpd with hadoop using python in the below format

IP address    Count of IP   Pages accessed by IP address

I know that apache log files will be of two kinds

  1. access_logs

  2. error_logs

but i am really unable to understand the format of apache log files.

My apache log file content is something like below

::1 - - [29/Oct/2012:15:20:15 +0530] "GET /phpMyAdmin/ HTTP/1.1" 200 6961 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1"
::1 - - [29/Oct/2012:15:20:16 +0530] "GET /phpMyAdmin/js/cross_framing_protection.js?ts=1336063073 HTTP/1.1" 200 331 "http://localhost/phpMyAdmin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1"
::1 - - [29/Oct/2012:15:20:16 +0530] "GET /phpMyAdmin/js/jquery/jquery-1.6.2.js?ts=1336063073 HTTP/1.1" 200 92285 "http://localhost/phpMyAdmin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1"

Can anyone please explain me the structure of above/apache log files

I am confused on how to process the the log file with the data Ip address, countof ip address, pages accessed by ip address

Can anyone let me know how we can process the apache log files with haddop using python and above information and store the result in the above mentioned format

Also can anyone please provide a basic code in python for processing the apache log files in the above format, so that i will get an real time idea on how to process the files with python code and will extend them according to needs


Source: (StackOverflow)

Redirect sysout & syserr output(console) to log file in tomcat7

I want to redirect my sysout or syserr console output to log file in tomcat7


Source: (StackOverflow)

Eclipse is not working after download

I downloaded the eclipse from this site: http://www.eclipse.org/downloads/ (Eclipse classic 4.2.1)

I extracted the zip folder and ran the exe file -> eclipse (With the symbol of a circle of eclipse)

I get this error message: An error has occurred. see the log file...

I saw the log file is very long and not understood, I did not find the problem.

can anyone help me?

I think that the error that was written in the log file:

java.lang.RuntimeException: Application "org.eclipse.ui.ide.workbench" could not be found in the registry. The applications available are: org.eclipse.ant.core.antRunner, org.eclipse.equinox.app.error, org.eclipse.equinox.p2.director, org.eclipse.equinox.p2.garbagecollector.application, org.eclipse.pde.junit.runtime.uitestapplication, org.eclipse.pde.junit.runtime.legacytestapplication, org.eclipse.pde.junit.runtime.coretestapplication, org.eclipse.pde.junit.runtime.coretestapplicationnonmain, org.eclipse.pde.junit.runtime.nonuithreadtestapplication.
    at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:248)
    at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

Source: (StackOverflow)

Scheduled task, file output not created

I wrote a c-program that outputs a timestamp to a log-file. When its executed on windows server 2008 rc2 the logfile with corresponding timestamp is created correctly. But when the program is executed by task scheduler (from admin account), the logfile isn't created. Does someone know why?

int main(int argc, char* argv[])
{
   int count = 300;
   time_t rawtime;
   struct tm* timeinfo;

   time(&rawtime);
   timeinfo = localtime(&rawtime);

   printf("System resumed at: %s\n", asctime(timeinfo));

   log("System resumed at: ");
   log(asctime(timeinfo));

   while(count > 0)
   {
      printf("\rClosing in %ds.", count);
      Sleep(1000);
      printf("\r                      ");
      count--;
   }

   return EXIT_SUCCESS;
}

void log(char *message)
{
   FILE *file;

   file = fopen(LOGFILE, "a");

   if (file == NULL) {
      fputs("Error opening file.\n", stderr);
      return;
   }

   fputs(message, file);

   if (file)
      fclose(file);
}

Source: (StackOverflow)

Python find most recent File and get the size

I am trying to get python to find the most recent file in a directory and get the file size. I have tried a couple different methods using "sorted" and "os.path" but nothing seems to work quite right. Here is sample code.

 filepath='/path/to/files'

 files = sorted([ 
    f for f in os.listdir(filepath) if f.startswith('spam')])


 print "Most recent file = %s" % (files[-1],)

 recent = files[-1]

 filesize = os.path.getsize(recent)

 #print "File size = %s" % (filesize)

This grabs the most recent file, but errors out when trying to find the size displaying it doesnt have a directory to search. So I went a different method like this.

import os,sys
from stat import *
from os.path import join

for (dirname, dirs, files) in os.walk('/path/to/file'):
    for filename in files:
            if filename.startswith('.tar.gz'):
                    thefile = os.path.join(dirname,filename)
                    size = os.path.getsize(thefile)
                    if size == 0
                    print "File %s has 0 data!" % thefile
                            exit 2
                    else print "File %s is good!" %thefile
                            exit 0

This one exits out with error invalid sytax on "size = 0"

Any help is much appreciated!


Source: (StackOverflow)

How handle Log File in in selenium webdriver using java

I don't know how to handle log file in selenium webdriver using java .. i wanna perform following task in log file : - store label of each link of website page in log file - Read that stored label one by one

is it possible in selenium ...?


Source: (StackOverflow)