{
  "id": 76313,
  "title": "Proper logging for Kernel Competitions",
  "url": "/competitions/quora-insincere-questions-classification/discussion/76313",
  "author_name": "higepon",
  "post_date": "2019-01-01T06:52:38.793000",
  "votes": 0,
  "comment_count": 9,
  "views": 0,
  "content": "<p>Hi there, I'm new to Kernel competitions and have a question about logging.</p>\n\n<p>When you're tweaking your kernel, you typically want to observe some important values. For example, local CV score, time spent on a particular part of your code and etc. If you're using local python scripts or Jupyter notebooks, it's easy you just print the values to stdout using print function.</p>\n\n<p>But print doesn't always work for kernels.</p>\n\n<ul>\n<li>(A) What if you're disconnected while a kernel is running (eg. when you leave Starbucks and go home :)</li>\n<li>(B) Kaggle kernel sometimes stop printing to stdout, even though the kernel is running w/o any issues.</li>\n<li>(C) You may run a kernel and commit at the same time.</li>\n</ul>\n\n<p>How do you all tackle the logging issue? I'm thinking of writing them into a file, but I may be missing something obvious.</p>\n\n<p>thanks!</p>",
  "messages": [
    {
      "id": 448561,
      "postDate": "2019-01-01T13:52:59.913Z",
      "content": "<p>Haven't encountered anything that prints can't produce results. You can set a new cell for print alone.</p>",
      "rawMarkdown": "Haven't encountered anything that prints can't produce results. You can set a new cell for print alone.",
      "votes": 1,
      "replies": [
        {
          "id": 448769,
          "postDate": "2019-01-02T03:45:09.130Z",
          "content": "<p>For me print is not working, when I am committing through notebook. But, when I am committing through scripts it is working. But the problem, with scripts is, if there is a bug say \"variable not defined\", it won't show the error, but it stops working saying an \"error happened\". that is a pain, then I have to run the code in a notebook cell to find the wrror. </p>",
          "rawMarkdown": "For me print is not working, when I am committing through notebook. But, when I am committing through scripts it is working. But the problem, with scripts is, if there is a bug say \"variable not defined\", it won't show the error, but it stops working saying an \"error happened\". that is a pain, then I have to run the code in a notebook cell to find the wrror. ",
          "votes": 1
        },
        {
          "id": 448844,
          "postDate": "2019-01-02T08:01:48.730Z",
          "content": "<p><a href=\"/s4sarath\">@s4sarath</a>\nThe notebook runs from top to bottom, and each cell runs independently. Normally, the error message will indicate which line of code is faulty, and you can view the line of code to correct it.</p>",
          "rawMarkdown": "@s4sarath\nThe notebook runs from top to bottom, and each cell runs independently. Normally, the error message will indicate which line of code is faulty, and you can view the line of code to correct it.",
          "votes": 2
        }
      ]
    },
    {
      "id": 448718,
      "postDate": "2019-01-01T23:28:24.037Z",
      "content": "<p>Use the logging library.</p>\n\n<p><code>import logging</code></p>\n\n<p><code>logging.basicConfig(filename='log.txt',level=logging.DEBUG, format='%(asctime)s %(message)s')</code></p>\n\n<p>and at every relevant step put:</p>\n\n<p><code>logging.info('some message e.g. step finished')</code></p>\n\n<p>One of the outputs of your commit will be a log.txt file that you can inspect.</p>\n\n<p>You can also log tracebacks from error using <code>try</code> and <code>logging.exception</code>.</p>",
      "rawMarkdown": "Use the logging library.\n\n`import logging`\n\n`logging.basicConfig(filename='log.txt',level=logging.DEBUG, format='%(asctime)s %(message)s')`\n\nand at every relevant step put:\n\n`logging.info('some message e.g. step finished')`\n\nOne of the outputs of your commit will be a log.txt file that you can inspect.\n\nYou can also log tracebacks from error using `try` and `logging.exception`.",
      "votes": 2,
      "replies": [
        {
          "id": 448729,
          "postDate": "2019-01-02T00:39:28.823Z",
          "content": "<p>Thank you!\nI guess you check log.txt from output tab of your kernel?</p>",
          "rawMarkdown": "Thank you!\nI guess you check log.txt from output tab of your kernel?",
          "votes": 1
        },
        {
          "id": 448865,
          "postDate": "2019-01-02T09:08:30.020Z",
          "content": "<p>Exactly. And that's relevant in notebooks, as the printed output is lost if you close them.</p>",
          "rawMarkdown": "Exactly. And that's relevant in notebooks, as the printed output is lost if you close them."
        }
      ]
    },
    {
      "id": 448434,
      "postDate": "2019-01-01T06:52:38.793Z",
      "content": "<p>Hi there, I'm new to Kernel competitions and have a question about logging.</p>\n\n<p>When you're tweaking your kernel, you typically want to observe some important values. For example, local CV score, time spent on a particular part of your code and etc. If you're using local python scripts or Jupyter notebooks, it's easy you just print the values to stdout using print function.</p>\n\n<p>But print doesn't always work for kernels.</p>\n\n<ul>\n<li>(A) What if you're disconnected while a kernel is running (eg. when you leave Starbucks and go home :)</li>\n<li>(B) Kaggle kernel sometimes stop printing to stdout, even though the kernel is running w/o any issues.</li>\n<li>(C) You may run a kernel and commit at the same time.</li>\n</ul>\n\n<p>How do you all tackle the logging issue? I'm thinking of writing them into a file, but I may be missing something obvious.</p>\n\n<p>thanks!</p>",
      "rawMarkdown": "Hi there, I'm new to Kernel competitions and have a question about logging.\n\nWhen you're tweaking your kernel, you typically want to observe some important values. For example, local CV score, time spent on a particular part of your code and etc. If you're using local python scripts or Jupyter notebooks, it's easy you just print the values to stdout using print function.\n\nBut print doesn't always work for kernels.\n\n- (A) What if you're disconnected while a kernel is running (eg. when you leave Starbucks and go home :)\n- (B) Kaggle kernel sometimes stop printing to stdout, even though the kernel is running w/o any issues.\n- (C) You may run a kernel and commit at the same time.\n\n\nHow do you all tackle the logging issue? I'm thinking of writing them into a file, but I may be missing something obvious.\n\nthanks!"
    },
    {
      "id": 448624,
      "postDate": "2019-01-01T17:48:01.343Z",
      "content": "<p>I guess commit is the best way to go to keep track of results, run time, print() etc.\nI think there is no limit on how many commits per day you do.\nWhen I use notebook, often the output cells get wiped after a while (maybe an issue with my browser).</p>",
      "rawMarkdown": "I guess commit is the best way to go to keep track of results, run time, print() etc.\nI think there is no limit on how many commits per day you do.\nWhen I use notebook, often the output cells get wiped after a while (maybe an issue with my browser).",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 448728,
          "postDate": "2019-01-02T00:38:36.600Z",
          "content": "<p>Thanks for your reply!</p>\n\n<blockquote>\n  <p>often the output cells get wiped after a while</p>\n</blockquote>\n\n<p>That happened to me a lot.</p>\n\n<blockquote>\n  <p>I guess commit is the best way to go to keep track of results, run time, print() etc.</p>\n</blockquote>\n\n<p>This is a newbie question, but where exactly can you see the output of print() when commit?</p>",
          "rawMarkdown": "Thanks for your reply!\n&gt; often the output cells get wiped after a while\n\nThat happened to me a lot.\n\n&gt; I guess commit is the best way to go to keep track of results, run time, print() etc.\n\nThis is a newbie question, but where exactly can you see the output of print() when commit?\n\n"
        },
        {
          "id": 448733,
          "postDate": "2019-01-02T00:49:17.603Z",
          "content": "<p>I got it.\nWe can see cell output from committed kernel - Open Version</p>",
          "rawMarkdown": "I got it.\nWe can see cell output from committed kernel - Open Version"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 448561,
      "author_name": "Bai",
      "author_url": "",
      "post_date": "2019-01-01T13:52:59.913000",
      "content": "<p>Haven't encountered anything that prints can't produce results. You can set a new cell for print alone.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 448769,
          "author_name": "aintnosunshine",
          "author_url": "",
          "post_date": "2019-01-02T03:45:09.130000",
          "content": "<p>For me print is not working, when I am committing through notebook. But, when I am committing through scripts it is working. But the problem, with scripts is, if there is a bug say \"variable not defined\", it won't show the error, but it stops working saying an \"error happened\". that is a pain, then I have to run the code in a notebook cell to find the wrror. </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 448844,
          "author_name": "Bai",
          "author_url": "",
          "post_date": "2019-01-02T08:01:48.730000",
          "content": "<p><a href=\"/s4sarath\">@s4sarath</a>\nThe notebook runs from top to bottom, and each cell runs independently. Normally, the error message will indicate which line of code is faulty, and you can view the line of code to correct it.</p>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 448718,
      "author_name": "ManuelSH",
      "author_url": "",
      "post_date": "2019-01-01T23:28:24.037000",
      "content": "<p>Use the logging library.</p>\n\n<p><code>import logging</code></p>\n\n<p><code>logging.basicConfig(filename='log.txt',level=logging.DEBUG, format='%(asctime)s %(message)s')</code></p>\n\n<p>and at every relevant step put:</p>\n\n<p><code>logging.info('some message e.g. step finished')</code></p>\n\n<p>One of the outputs of your commit will be a log.txt file that you can inspect.</p>\n\n<p>You can also log tracebacks from error using <code>try</code> and <code>logging.exception</code>.</p>",
      "votes": 2,
      "replies": [
        {
          "id": 448729,
          "author_name": "higepon",
          "author_url": "",
          "post_date": "2019-01-02T00:39:28.823000",
          "content": "<p>Thank you!\nI guess you check log.txt from output tab of your kernel?</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 448865,
          "author_name": "ManuelSH",
          "author_url": "",
          "post_date": "2019-01-02T09:08:30.020000",
          "content": "<p>Exactly. And that's relevant in notebooks, as the printed output is lost if you close them.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 448624,
      "author_name": "",
      "author_url": "",
      "post_date": "2019-01-01T17:48:01.343000",
      "content": "<p>I guess commit is the best way to go to keep track of results, run time, print() etc.\nI think there is no limit on how many commits per day you do.\nWhen I use notebook, often the output cells get wiped after a while (maybe an issue with my browser).</p>",
      "votes": 1,
      "replies": [
        {
          "id": 448728,
          "author_name": "higepon",
          "author_url": "",
          "post_date": "2019-01-02T00:38:36.600000",
          "content": "<p>Thanks for your reply!</p>\n\n<blockquote>\n  <p>often the output cells get wiped after a while</p>\n</blockquote>\n\n<p>That happened to me a lot.</p>\n\n<blockquote>\n  <p>I guess commit is the best way to go to keep track of results, run time, print() etc.</p>\n</blockquote>\n\n<p>This is a newbie question, but where exactly can you see the output of print() when commit?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 448733,
          "author_name": "higepon",
          "author_url": "",
          "post_date": "2019-01-02T00:49:17.603000",
          "content": "<p>I got it.\nWe can see cell output from committed kernel - Open Version</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "448561": "Haven't encountered anything that prints can't produce results. You can set a new cell for print alone.",
    "448718": "Use the logging library.\n\n`import logging`\n\n`logging.basicConfig(filename='log.txt',level=logging.DEBUG, format='%(asctime)s %(message)s')`\n\nand at every relevant step put:\n\n`logging.info('some message e.g. step finished')`\n\nOne of the outputs of your commit will be a log.txt file that you can inspect.\n\nYou can also log tracebacks from error using `try` and `logging.exception`.",
    "448434": "Hi there, I'm new to Kernel competitions and have a question about logging.\n\nWhen you're tweaking your kernel, you typically want to observe some important values. For example, local CV score, time spent on a particular part of your code and etc. If you're using local python scripts or Jupyter notebooks, it's easy you just print the values to stdout using print function.\n\nBut print doesn't always work for kernels.\n\n- (A) What if you're disconnected while a kernel is running (eg. when you leave Starbucks and go home :)\n- (B) Kaggle kernel sometimes stop printing to stdout, even though the kernel is running w/o any issues.\n- (C) You may run a kernel and commit at the same time.\n\n\nHow do you all tackle the logging issue? I'm thinking of writing them into a file, but I may be missing something obvious.\n\nthanks!",
    "448624": "I guess commit is the best way to go to keep track of results, run time, print() etc.\nI think there is no limit on how many commits per day you do.\nWhen I use notebook, often the output cells get wiped after a while (maybe an issue with my browser)."
  }
}