Last active
December 14, 2015 05:28
-
-
Save rduplain/5035223 to your computer and use it in GitHub Desktop.
Simple dated file logging script for hubot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Simple room logging, to log/yyyy-mm-dd.log files for all rooms. | |
# Log format is: isodate - room <user> text | |
# | |
# Dependencies: | |
# None | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# None | |
# | |
# Author: | |
# rduplain | |
fs = require 'fs' | |
path = require 'path' | |
util = require 'util' | |
date_filename = (date = new Date) -> | |
# zero-fill month and day | |
zero = '00' | |
util.format( | |
'%s-%s-%s.log', | |
date.getFullYear(), | |
(zero + (date.getMonth() + 1).toString()).slice(-zero.length), | |
(zero + date.getDate().toString()).slice(-zero.length)) | |
module.exports = (robot) -> | |
dir = 'log' | |
if not fs.existsSync(dir) | |
fs.mkdirSync(dir) | |
robot.hear /.*$/i, (msg) -> | |
# Do not log private messages. | |
if msg.message.room | |
now = new Date | |
log = util.format( | |
'%s - %s <%s> %s\n', | |
now.toISOString(), | |
msg.message.room, | |
msg.message.user.name, | |
msg.message.text) | |
fs.appendFile(path.join(dir, date_filename()), log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment