{"action":"closed","issue":{"url":"https://api.github.com/repos/expressjs/morgan/issues/81","labels_url":"https://api.github.com/repos/expressjs/morgan/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/expressjs/morgan/issues/81/comments","events_url":"https://api.github.com/repos/expressjs/morgan/issues/81/events","html_url":"https://github.com/expressjs/morgan/issues/81","id":105450154,"number":81,"title":"Log File Getting Truncated","user":{"login":"mayur-arora","id":7187867,"avatar_url":"https://avatars.githubusercontent.com/u/7187867?v=3","gravatar_id":"","url":"https://api.github.com/users/mayur-arora","html_url":"https://github.com/mayur-arora","followers_url":"https://api.github.com/users/mayur-arora/followers","following_url":"https://api.github.com/users/mayur-arora/following{/other_user}","gists_url":"https://api.github.com/users/mayur-arora/gists{/gist_id}","starred_url":"https://api.github.com/users/mayur-arora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mayur-arora/subscriptions","organizations_url":"https://api.github.com/users/mayur-arora/orgs","repos_url":"https://api.github.com/users/mayur-arora/repos","events_url":"https://api.github.com/users/mayur-arora/events{/privacy}","received_events_url":"https://api.github.com/users/mayur-arora/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/expressjs/morgan/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"milestone":null,"comments":9,"created_at":"2015-09-08T19:09:39Z","updated_at":"2015-09-09T05:27:40Z","closed_at":"2015-09-09T05:27:40Z","body":"So I looked around for this one a lot, could not find anything. I have been able to log using morgan in a file but the file keeps getting truncated with every entry. I created a module for morgan logging:\r\n  \r\n```js\r\nvar morgan = require(\"morgan\");\r\nvar util = require(\"util\");\r\nvar morganConfig = require(\"config\").morganConfig;\r\nvar fs = require(\"fs\");\r\n\r\nmorgan.token(\"dump_res_on_err\", function (req, res) {\r\n    if (res.statusCode >= 400) {\r\n        return util.inspect(res);\r\n    }\r\n    else return \"{}\";\r\n});\r\n\r\nmorgan.token(\"date-time\", function (req, res) {\r\n    return Date().toLocaleString();\r\n})\r\n\r\nmorgan.format(\"loopback-log\", \"Morgan :date-time :method :url :status :response-time ms :dump_res_on_err\");\r\n\r\n\r\nif (morganConfig.mode === \"console\") {\r\n    module.exports.log = morgan(\"loopback-log\");\r\n}\r\nelse if (morganConfig.mode === \"file\") {\r\n    var accessLogStream = fs.createWriteStream(\"/Users/mayur.arora/Desktop/morgan.log\", {flags: 'a'});\r\n    module.exports.log = morgan(\"loopback-log\", {\r\n        stream: accessLogStream\r\n    });\r\n}\r\n```\r\nand in my server file , just use this:\r\n```js\r\napp.use(\"/api/*\",morganLogger.log);\r\n```\r\nIt works ; the log is being written to but as I said it keeps getting truncated. Pick the file to be written to from a config \r\n```js\r\n \"morganConfig\":{\r\n    \"mode\":\"file\",\r\n    \"fileName\":\"/var/log/a/b/c/nodeServerLogFile.log\"\r\n  }\r\n```"}}