This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Goof's profile picture

[ LogAPI ] v1.72 Logging made easier!

Started by Goof, 02 February 2014 - 02:59 PM
Goof #1
Posted 02 February 2014 - 03:59 PM
LogAPI 1.72 - By Mikkel809h




Have you ever wanted to log things easier, without having to make new functions and new stuffz?

Then try my LoggingAPI!



What it does:

Makes logging easier, just by a few functioncalls


Features:

Store logs into the api's table, and save them later.

Save logs directly.

Specify a custom path

and much more to come…

Debug-variable: Set the variable to true and the api will show debug

When you load the api, it checks if it is outdated.. if it is, it wants you to use log.update() in your program.


Usage:


First of all, you start the api ( Not os.loadAPI )


shell.run("logapi") -- When running this, it creates a global table called "log"

Then you can start using it:


shell.run("logapi")

log.setPath("testPath") -- set your path first.
log.add("Hello_This is a testing log") -- add..

-- other method:

-- add to a new file:
log.setPath("testPath_1") -- set path first
log.store( "Hi", "-SAVE" ) -- store

-- Delete log:

log.delete( "somepath_to_your_log" )

-- Update:

log.update() -- Run this on startup... ( no returns... It directly updates to newest version, if any )



Changelog

v1.72:

Major update of main functions

No more confusing stuff If any, tell me

log.update directly updates. No Printing screen


v0.75:

Update function

Times in logs. ( tell me if something is wrong with this… )


Major Update.

v0.5:

Major release



Download:




CC:



pastebin get 1mwhBiW9 logapi





Happy Logging :D/>
Edited on 11 June 2014 - 01:25 PM
H4X0RZ #2
Posted 02 February 2014 - 04:51 PM
I like It :)/>

Maybe add log levels like the ones of Bukkit,for example 'fine','finer','finest' and 'info' :)/>
surferpup #3
Posted 02 February 2014 - 05:39 PM
This is cool. You could incorporate the functionality of my Real World Time API for snagging real world date and timestamps. Let me know if it useful for your project.
oeed #4
Posted 03 February 2014 - 02:21 AM
Saving the log to a file, for some bizarre reason I hadn't thought of that, consdiering 90% of logs are saved to a file.

This way the screen is polluted with stupid 'hello', '123' messages, which are particularly annoying if you're using a buffer.

Edited on 03 February 2014 - 02:29 AM
TechMasterGeneral #5
Posted 03 February 2014 - 12:55 PM
This is awesome… I'm gonna try implementing it in my CCMC… if i get it working right i'll add you to the credits
Lyqyd #6
Posted 03 February 2014 - 03:33 PM
Moved to APIs and Utilities.
Goof #7
Posted 06 February 2014 - 10:26 AM
Hello- Im back from a long internet-breakdown… My internet router/modem went totally crazy and i had to buy a new, and as i got that, i also bought some more bandwidth. Yaay!

On topic:

Thanks for all the response, and sorry for the late answer.

I like It :)/>

Maybe add log levels like the ones of Bukkit,for example 'fine','finer','finest' and 'info' :)/>


Hmm, like a section- saved by the type?


log.add("Hello","warning") – just a test.. This hasn't been implemented 'yet'

^^ would output:

  -WARNING: "Hello"


Something like that? or could you explain more?

This is cool. You could incorporate the functionality of my Real World Time API for snagging real world date and timestamps. Let me know if it useful for your project.

It sounds really useful, mostly because then it would be able to see what date-time-seconds etc. the log were saved. I don't quite know if im going to code my own real world time api, but to start with, i "Might" use your api and give you some credits:D





Thanks for all responses.

I hope the next release will be uploaded in some days ( or maybe later today? )
surferpup #8
Posted 06 February 2014 - 12:33 PM
It sounds really useful, mostly because then it would be able to see what date-time-seconds etc. the log were saved. I don't quite know if im going to code my own real world time api, but to start with, i "Might" use your api and give you some credits:D

I just thought you might find it useful instead of having to code it yourself. I really don't care about the credits:) If you like it, leave a comment on the page and up vote it.
lebalusch #9
Posted 09 June 2014 - 12:18 AM
Noob question alert-

so this is the test script (named test) i made


os.loadAPI("log")

log.add("Hello") -- add "Hello" to the log file
log.delete("testLOG") -- deletes the log file
log.store(...,"-STORE_save_log") -- this functions allows you to store all possible logs into its table.
--And by setting the last parameter, you tell it to save the table with logs.
log.setPath("testLOG") -- Sets the path to your log file. If not exists then it creates a new.
print("done")

so Why does this not work? i have also tried to make the file testLOG just incase it needs the file to exist at the start. all files are store as if you lay a new pc and just edit test. so i guess in path "test/"
Edited on 08 June 2014 - 10:20 PM
Goof #10
Posted 09 June 2014 - 12:51 AM
Hmm

Oh wait… Yeah, its because i forgot to change the usage from the newer version..

Here you go:


os.loadAPI("log")
log.setPath("ss") -- set your path first.
log.add("Hello") -- add..

-- add to a new file:
log.setPath("sa") -- set path first
log.store( "Hi", "-STORE_save_log" ) -- store


Thanks for that report :D/>
lebalusch #11
Posted 10 June 2014 - 12:01 AM
Hmm

Oh wait… Yeah, its because i forgot to change the usage from the newer version..

Here you go:


os.loadAPI("log")
log.setPath("ss") -- set your path first.
log.add("Hello") -- add..

-- add to a new file:
log.setPath("sa") -- set path first
log.store( "Hi", "-STORE_save_log" ) -- store


Thanks for that report :D/>

thanks for the quick reply. Sadly just using the code that you left i am still getting a error
" log:63: attempt to index ? (a nil value) "
using
  • VERSION_LOGAPI=0.76
Goof #12
Posted 10 June 2014 - 03:26 PM
Hmm

Oh wait… Yeah, its because i forgot to change the usage from the newer version..

Here you go:


os.loadAPI("log")
log.setPath("ss") -- set your path first.
log.add("Hello") -- add..

-- add to a new file:
log.setPath("sa") -- set path first
log.store( "Hi", "-STORE_save_log" ) -- store


Thanks for that report :D/>

thanks for the quick reply. Sadly just using the code that you left i am still getting a error
" log:63: attempt to index ? (a nil value) "
using
  • VERSION_LOGAPI=0.76

New Update! 0.9 ( Made it return false if opening of file didnt work )

Try to reproduce that error… It doesnt seem to happen for me.

Are you using a custom FS?

Are you writing to a readOnly file?

Did you try reboot the computer to reproduce?


Atm im just looking further into the api to find any clues on that "bug"


~ Mikk809h
lebalusch #13
Posted 10 June 2014 - 05:28 PM
This is the log file
Spoiler
this is the code used to get it (also using the api named as log obviously)
That is the result now so working.

Things I worked out myself that you might want to put in your instructions up top.
1. you need to make a directory called logapi
2. in that directory you need to make a file called log.
3. log.setPath() function does not mean the path you want the log set to but just the header of the log it writes. This is not very clear maybe a change of name to log.headerPath()
4. line 202 print("type \"log.update\" in your program to update") is a tad confusing when you get it pop up because you would only get it pop up if you have done an update i guess. so i knew i had already called the update. so maybe a little bit of rework with the text in this area.


IDEAS for the future: Apart from making your "how to use" a little bit more clear i would love to see a function that you could set the directory you write too and the name of the file. some thing like log.logPath("/logs/testlog") and log.logName("testlog") although if you are setting the path you could create the file if it does not exist from that i guess.

But thank you in its current format it does the job and does indeed have a use in my future builds, diamonds to you :-)
Edited on 12 June 2014 - 09:52 AM
Goof #14
Posted 10 June 2014 - 06:35 PM
Hello Again.


I've just pushed a new update to the api, ( almost a rewrite )
The only thing, confusing me is what you mean, by the log.logPath.. I think im going to remove the invisible logging feature, since its making me ( and others ) confused of which is which.


New update is comming in …. 5 mins.

Stay tuned


UPDATED to 1.72 - A number of changes, to make it more stable.

Read OP for new usage of my logAPI



Thanks for helping me out, making everything work smoothly.

~Mikk809h
Edited on 10 June 2014 - 04:49 PM
lebalusch #15
Posted 10 June 2014 - 08:52 PM
Hello Again.


I've just pushed a new update to the api, ( almost a rewrite )
The only thing, confusing me is what you mean, by the log.logPath.. I think im going to remove the invisible logging feature, since its making me ( and others ) confused of which is which…..

….Thanks for helping me out, making everything work smoothly.

ok so the log.logPath() was just an idea for a function to ask me the route to the log file it would want a reply in the () like "/folder1/log" path, route ,link that kind of way of thinking.

As for the helping out your welcome we are a community and i benefit from your work as i get to use it and also see ideas of how to do certain things in your code too. We all benefit. :)/>
lebalusch #16
Posted 10 June 2014 - 10:06 PM
back to nothing working again.
version 1.73

can you please supply the names of what and where you have everything saved.

i can see a possible fault as you have changed the file name to " logapi " but not the code to call anything. should i be using this "logapi.setPath("testPath") " instead of this "log.setPath("testPath")" ??
Goof #17
Posted 11 June 2014 - 03:23 PM
back to nothing working again.
version 1.73

can you please supply the names of what and where you have everything saved.

i can see a possible fault as you have changed the file name to " logapi " but not the code to call anything. should i be using this "logapi.setPath("testPath") " instead of this "log.setPath("testPath")" ??

Im going to explain further in details:

My new version is (when runned) Creating a Global table, called "log"

In the table "log" all the functions exist.

So even if the logpath is "/something/WeirdAPI" then you still call it as

log.setPath('E/ETest')


This quick example below, works ingame.


shell.run("logapi") -- my path to the logapi i downloaded

log.setPath("ss") -- set your path first.
log.add("Hello") -- add..

-- add to a new file:
log.setPath("sa") -- set path first
log.store( "Hi", "-SAVE" ) -- store


This update ( 1.73 ) has removed all the confusing stuff ( the same as 1.72 )

But the new thing in 1.7X is that The logAPI itself wont save anything for debugging.
Of course you can enable the debug, to see whats wrong, if anything is wrong.

I have a feeling that you're running in a custom fs, ( maybe an OS? ) , which can ( Not does ), disable some of the fs handlings in my API.

And for your question:
should i be using this "logapi.setPath("testPath") " instead of this "log.setPath("testPath")" ??
No. You should not, since My API makes a global table ( called "log" ).
You can run all the functions with: log.anyfunction( x )


~Mikkel
lebalusch #18
Posted 11 June 2014 - 04:32 PM
Now run it on an emulator so there is no mods interfering
Spoiler

Still not working.

is it possible to have 1.72 the one i had working since you changed it all its stopped working for me.

I run monster FTB
this is the ingame error i get. same line
Spoiler
Edited on 12 June 2014 - 09:52 AM
Goof #19
Posted 11 June 2014 - 09:34 PM
SpoilerNow run it on an emulator so there is no mods interfering




Still not working.

is it possible to have 1.72 the one i had working since you changed it all its stopped working for me.

I run monster FTB
this is the ingame error i get. same line
I have no clue why it isnt working.

I just tested this on several emulators, and ingame, but everything works.

As i asked before, are you overwriting anything related to the fs api?

Lemme show you some screenies:
Spoilerhttp://imgur.com/a/SFftU/embed

OR for "better" view:

http://jsfiddle.net/7AxVc/

And just a note: I added a tostring() around, when saving the logs… thats why the newest version is 1.736 – in 1.736 I just made the program check if http was enabled

Did you try to wipe the computer, then only download logapi, then make your test program again?


I really dont know what is causing your troubles. I need ways to reproduce.

Wait… Is HTTP enabled? if so, did you whitelist all websites? Because my API uses a website called:

http://www.timeanddate.com

.. Maybe thats not whitelisted?
Edited on 11 June 2014 - 07:45 PM
lebalusch #20
Posted 12 June 2014 - 11:47 AM
Hi Mikk809h,
Didn't realise you could white list sites or black list them. I am testing on my own real life laptop. in single player , using FTB monster. when i test your scripts i lay a new computercraft block (gold) so shouldn't be a problem. maybe if you add some code to make a point of white listing it before you try to go to the site this might help. but i have had your script working before you made the big changes. Was you using that HTTP call before the big changes if so its not that being a problem. but i do think you should code in white listing the site before calling it.

p.s how do you do these spoilers. they save on loads of space in comments.
Edited on 12 June 2014 - 09:53 AM
KingofGamesYami #21
Posted 12 June 2014 - 02:31 PM
Hi Mikk809h,
Didn't realise you could white list sites or black list them. I am testing on my own real life laptop. in single player , using FTB monster. when i test your scripts i lay a new computercraft block (gold) so shouldn't be a problem. maybe if you add some code to make a point of white listing it before you try to go to the site this might help. but i have had your script working before you made the big changes. Was you using that HTTP call before the big changes if so its not that being a problem. but i do think you should code in white listing the site before calling it.

p.s how do you do these spoilers. they save on loads of space in comments.
You cannot whitelist a site from code. It has to be done manually in the config. This was added in the CC 1.63 update, before which http was simply true (enabled) or false (disabled).
Goof #22
Posted 12 June 2014 - 04:00 PM
Hi Mikk809h,
Didn't realise you could white list sites or black list them. I am testing on my own real life laptop. in single player , using FTB monster. when i test your scripts i lay a new computercraft block (gold) so shouldn't be a problem. maybe if you add some code to make a point of white listing it before you try to go to the site this might help. but i have had your script working before you made the big changes. Was you using that HTTP call before the big changes if so its not that being a problem. but i do think you should code in white listing the site before calling it.

p.s how do you do these spoilers. they save on loads of space in comments.
Well, All my HTTP calls have had this feature, and they access the timeanddate.com webpage. Maybe its because you updated to newest version of cc?
Then youj forgot to add www.timeanddate.*

And as KingofGamesYami said:

You cannot whitelist a site from code. It has to be done manually in the config. This was added in the CC 1.63 update, before which http was simply true (enabled) or false (disabled).


And i dont think it would be a great idea, to allow programs to whiltelist webpages themselfes, since that could cause a program to acces a malicious webpage ( thats an example )

But I dont quite know how to detect if certain webpages are whitelisted or not.. Maybe someone can point out the whitelist detection code?

Thanks
lebalusch #23
Posted 12 June 2014 - 05:55 PM
Hi guys,
Yes it makes sense to lock programs out from being able to do that. The pack FTB Monster is currently using is ComputerCraft 1.58
could someone be nice enough to talk me through how to set said HTTP to being on the white list as i have opened the config file and there is no mention to allowed http's on a white list there.
i all ready know that HTTP access is true as in FTB its set to on by default.
(if you are playing vanilla MC its not just follow this http://www.computercraft.info/forums2/index.php?/topic/17533-how-to-enable-the-http-api/ )

# Enable the "http" API on Computers
B:enableAPI_http=true
KingofGamesYami #24
Posted 12 June 2014 - 06:15 PM
-snip-
There is no "whitelist" in CC 1.58. It was changed to whitelist in CC 1.63, which isn't relevant since you are not using it. If the pastebin program works, http is enabled fully. If not, in CC 1.63 you have to either
1) add the site to the whitelist
or
2) enable all sites (just put a "*" I believe, I'm not sure though)
Edited on 12 June 2014 - 04:15 PM
lebalusch #25
Posted 12 June 2014 - 06:20 PM
-snip-
There is no "whitelist" in CC 1.58. It was changed to whitelist in CC 1.63, which isn't relevant since you are not using it. If the pastebin program works, http is enabled fully. If not, in CC 1.63 you have to either
1) add the site to the whitelist
or
2) enable all sites (just put a "*" I believe, I'm not sure though)

Well does the program work correctly for you? If i have no whitelist due to the version i am running and the http access is turned on then the program should work….i guess? but it does not since the changes were made. Could you please try the program and let me know please.
KingofGamesYami #26
Posted 12 June 2014 - 06:57 PM
The version on pastebin is flawed on line 86/87, he forgot to add the end to this statement:

local function checkUpdate()
  if http then
    local check={}
    local pastebinCode="1mwhBiW9"
    local pdtSite="http://pastebin.com/raw.php?i=" .. pastebinCode
    check["update"]=http.get(pdtSite).readAll()
    check["oldVersion"]=VERSION_LOGAPI
    check["newVersion"]=string.match(check["update"], "(%d+.%d+).-")
    return tonumber(check["newVersion"])>tonumber(check["oldVersion"]), check["newVersion"], check["oldVersion"]
  else
    return false, VERSION_LOGAPI, VERSION_LOGAPI
end
Corrected code:

local function checkUpdate()
  if http then
    local check={}
    local pastebinCode="1mwhBiW9"
    local pdtSite="http://pastebin.com/raw.php?i=" .. pastebinCode
    check["update"]=http.get(pdtSite).readAll()
    check["oldVersion"]=VERSION_LOGAPI
    check["newVersion"]=string.match(check["update"], "(%d+.%d+).-")
    return tonumber(check["newVersion"])>tonumber(check["oldVersion"]), check["newVersion"], check["oldVersion"]
  else
    return false, VERSION_LOGAPI, VERSION_LOGAPI
  end
end
lebalusch #27
Posted 13 June 2014 - 03:08 PM
Still not working for me even with the changes
using 1.737

getting this error now
Spoiler
And yes i have also tried it with the file being named "logapi"
Edited on 13 June 2014 - 01:18 PM
Xtansia #28
Posted 13 June 2014 - 04:22 PM
Still not working for me even with the changes
using 1.737

getting this error now
Spoiler
And yes i have also tried it with the file being named "logapi"

It's because the pattern that is being used to match the time and date on the webpage doesn't match the format of the time and date that the webpage is outputting.
Goof #29
Posted 13 June 2014 - 05:02 PM
Still not working for me even with the changes
using 1.737

getting this error now
Spoiler
And yes i have also tried it with the file being named "logapi"

It's because the pattern that is being used to match the time and date on the webpage doesn't match the format of the time and date that the webpage is outputting.

Try it now, with 1.738. Just added some more "tostring()" functions when writing the file

If that doesnt work, then go to the log it "wrote", ( if it did ), and see if the date is "HTTP_NOT_ENABLED" or "[TIME_NOT_RECEIVED] > #Error 404 #–> "


Thanks for reporting the "bugs"



And for the time being, im still asking for assistance, to check wether a webpage is whitelisted or not.



~Mikkel
Xtansia #30
Posted 13 June 2014 - 05:51 PM
-snip-

It's because your pattern is expecting the date and time in the form:
Friday 13. June 2014 12:00:00
But the webpage is outputting
Friday, 13 June 2014 12:00:00
Goof #31
Posted 13 June 2014 - 06:32 PM
-snip-

It's because your pattern is expecting the date and time in the form:
Friday 13. June 2014 12:00:00
But the webpage is outputting
Friday, 13 June 2014 12:00:00

Why does it then work on my own computer when testing?
Xtansia #32
Posted 13 June 2014 - 07:02 PM
Why does it then work on my own computer when testing?

My guess would be that the date and time get formatted differently based on where it's being viewed from.
Also it fetches the time for Odense, so not exactly useful for anybody else.
Goof #33
Posted 13 June 2014 - 07:57 PM
Why does it then work on my own computer when testing?

My guess would be that the date and time get formatted differently based on where it's being viewed from.
Also it fetches the time for Odense, so not exactly useful for anybody else.

hmm
That might be a bigger workaround i need to do, to make that work.

Hmm
Maybe i should remove the date info? What do you think?
lebalusch #34
Posted 14 June 2014 - 02:49 PM
If you remove that feature and have a working program we can use it while working on implementing that feature. At the moment its broke.