Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Logging to a file Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: January 28 2008 at 21:22 | IP Logged Quote jeffw_00

Hi - so I'm trying expand on how powerhome sends me an email when something is wrong. I want it to make a timestamped log entry, and I have many problems..

1) I want to get the day/time into a variable. I guessed the command is something like

ph_setvar_s(1,7,today())

but this doesn't work. nor do any permutations that i try.

2) originally I wanted to do something like

Launch App "echo <stuff> >> c:\insteon.log".

But this doesn't work. My guess it that it can't run the internal "echo" command.

So I wrote a very short perl script that does the work of Echo. That worked, but I'm surprised I can't use the echo command.

Anyway, does anyone know how to get today() into a variable, and/or if there's an easier way of doing this?

the rest of my script, BTW looks like.

ph_setvar_s(1,7," [LOCAL8]: INSTEON ERROR (count = {IERROR} ), Device [LOCAL1], Desired State [LOCAL2], Trigger [LOCAL3], Returned Status [LOCAL10]")

"c:\perl\bin\perl c:\insteon\writelog.pl [LOCAL7]"


thanks
/j
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: January 28 2008 at 22:31 | IP Logged Quote TonyNo

Multitasking here, but...

1. This returns what you would expect:
Code:
string(today(),"yyyy mm/dd h:mm:ss am/pm")


2. My CIDLOG macro logs to a file using ph_writefile.

Also, here's a formula from my TSTAT macro that logs...

Code:
ph_writefile( "c:\program files\powerhome\hvac.log", if( ph_fileexists( "c:\program files\powerhome\hvac.log") = 1, 0, 1), "{TSTAT TEMP T}" + " " + "{TSTAT SP}" + " " + "{TSTAT TEMP} " + {TSTAT RUN T} + " {CURTEMP}" + char(13) + char(10) )
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 28 2008 at 22:33 | IP Logged Quote dhoward

Jeff,

No problem . The output of the today() function is a datetime type and the ph_setvar_s function wants a string so we just have to convert it. This is good, because it also gives us an opportunity to get the date/time in a format we like. Try this:

ph_setvar_s(1,7,string(today(),"yyyy-mm-dd hh:mm:ss.fff"))

This should give you what you want.

To write to a log though, you don't even need to use echo or shell out to perl. You can do it all easily within PowerHome. I think this may give you what you want.

ph_writefile("c:\insteon.log",0,string(today(),"yyyy-mm-dd hh:mm:ss.fff") + " [LOCAL8]: INSTEON ERROR (count = {IERROR} ), Device [LOCAL1], Desired State [LOCAL2], Trigger [LOCAL3], Returned Status [LOCAL10]")

Hope this helps,

Dave.

**EDIT: Damn Tony...beat me to it . Great minds think alike it appears though.


Edited by dhoward - January 28 2008 at 22:35
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: January 28 2008 at 22:50 | IP Logged Quote TonyNo

Heh!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: January 28 2008 at 23:35 | IP Logged Quote jeffw_00

yeah - I missed ph_writefile - thanks guys. But this was the easy one. if you want a challenge, take another peek at

http://www.myx10.com/forum/forum_posts.asp?TID=1634&PN=1

and/or

http://www.myx10.com/forum/forum_posts.asp?TID=1628&PN=1

8-}

Thanks again
/j

Edited by jeffw_00 - January 28 2008 at 23:35
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum