btk
(The fish is still dead.)
November 11, 2015, 3:23pm
20
I’m using Logstash on one of my own servers to do this. In any SmartApp where I need to retain history, I add the following method and use it to log messages instead of log.debug():
stash.groovy
def stash(msg) {
log.debug(msg)
def dateNow = new Date()
// def isoDateNow = dateNow.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", location.timeZone)
def isoDateNow = dateNow.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
def json = "{"
json += "\"date\":\"${dateNow}\","
json += "\"isoDate\":\"${isoDateNow}\","
json += "\"name\":\"log\","
json += "\"message\":\"${msg}\","
This file has been truncated. show original
I also wrote another SmartApp that subscribes to all of my things and logs their events to the same Logstash server for easier correlation with the log entries:
/**
* Event Logger
*
* Copyright 2015 Brian Keifer
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "Logstash Event Logger",
namespace: "bkeifer",
author: "Brian Keifer",
description: "Log SmartThings events to a Logstash server",
This file has been truncated. show original