Re: Some newbie questions: http-client, logging.
Carl Gay <[email protected]> Wed, 3 Sep 2014 19:14:47 -0400
| Newsgroups | gmane.comp.lang.dylan.gwydion.devel |
|---|---|
| Message-ID | <CALekcH0L0WQNPaSAYXTd_3BRCU3R3FfgCaJCBsr9DHtVHos8PA@mail.gmail.com> |
--===============1559161183== Content-Type: multipart/alternative; boundary=001a1133a6aeef063205023166f0 --001a1133a6aeef063205023166f0 Content-Type: text/plain; charset=UTF-8 On Sun, Aug 31, 2014 at 12:55 AM, Carl Gay <[email protected]> wrote: > Hi Piotr. Some answers inline below... > > > On Fri, Aug 29, 2014 at 10:38 AM, Piotr Klibert < > [email protected]> wrote: > >> Hello list, >> >> Following recent HN submissions about OpenDylan I decided to take a >> closer look >> at the language. I wanted to learn it for a few years now, but when I last >> checked (yeards ago) the documentation was severly lacking. I'm very glad >> this >> improved. >> >> The first thing I decided to write was a simple "make http request" >> script, as >> usual for me. I encountered a couple of problems, which I'm sure you'll >> be able >> to answer immediately, but which I wasn't able to figure out yet. I should >> mention that I'm working with opendylan-2013.2-x86_64-linux from official >> download page and with http library from >> https://github.com/dylan-lang/http >> >> First, I'd like to get a list of headers out of response. I know I can >> check for >> a specific header with >> >> element(response.raw-headers, "connection", default: #f) >> >> and that I can iterate over headers values with for, but I found no way of >> getting the list of keys for <header-table>. I read bits of table.dylan, >> and >> noticed <vector-table> class and further entry-key method, but these seem >> to be >> internal and not exported. >> > > You can get the keys for any collection with key-sequence. > http://opendylan.org/books/drm/Collection_Operations#key-sequence > > If I recall correctly you can also get a header value with > element(response, "Connection", default: #f) > because the response is an instance of <message-headers-mixin>. > > >> >> >> Another thing: when the program terminates due to an error on runtime I >> get >> error message, like for example: >> >> "connection" is not present as a key for {<header-table>: size 1}. >> >> but that's all I see. Compared to other languages I'm used to working >> with it's >> ascetic, to say the least. I'm not asking for a full stacktrace, but a >> file and >> line where the error originates would be a huge help already. >> > > Debuggability could certainly be better. Right now the best you can do is > use gdb and you'll see mangled Dylan names. On OS X you can use lldb and > there's a name demangler. > > http://opendylan.org/documentation/getting-started-cli/debugging-with-gdb-lldb.html > > >> >> Further, when the program crashes, I see a >> >> Breaking into debugger. >> >> message. Am I correct in suspecting that this is something only available >> on >> some platforms, and not available for me on Linux? >> > > See above. > > >> >> >> Another question involves logging. In http-common I noticed >> >> define variable *debug-reads?* = #f; >> >> - is there any way of setting this variable from my own code? This: >> >> *debug-reads?* := #f; >> > > That was intended for debugging the http code itself and so isn't > exported. (It should be removed.) > > >> >> doesn't work and the compiler complains about an undefined binding. >> >> Similarly, in both http-client and http-common there are loggers defined, >> like >> this: >> >> define thread variable *http-common-log* :: <logger> >> = make(<logger>, >> name: "http.common", >> targets: list($stdout-log-target), >> level: $info-level); >> >> how can I adjust the level of the loggers to something else than the >> default? >> When I try to assign to *http-common-log*.level I get the error about the >> not >> being level-setter, which makes me suspect that logger instances should be >> immutable. But then I'm back to the previous question, where I can't >> reassign >> module-level variable from outside the module... >> > > Although the init keyword for a logger is level:, the accessors are > log-level and log-level-setter. You should be able to say > > *http-common-log*.log-level := $trace-level; > > You could also rebind *http-common-log* like this: > > dynamic-bind (*http-common-log* = your-logger) > http-get(url, ...) > end > > Looking at the logging code now, I see the naming is pretty confusing > since both the log- and logger- prefixes are used. I'll look at cleaning > that up. > FYI: Naming made more sane by this pull request: https://github.com/dylan-lang/logging/pull/8/files I haven't yet updated http code to use it. > > Keep the reports coming. :-) > -Carl > > >> Ok, that's it for now. I will probably come back with more questions soon >> :) >> >> >> Best regards, >> Piotr Klibert >> _______________________________________________ >> hackers mailing list >> [email protected] >> https://lists.opendylan.org/mailman/listinfo/hackers >> > > --001a1133a6aeef063205023166f0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail= _quote">On Sun, Aug 31, 2014 at 12:55 AM, Carl Gay <span dir=3D"ltr"><<a= href=3D"mailto:[email protected]" target=3D"_blank" class=3D"cremed">carlg= [email protected]</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex"><div dir=3D"ltr">Hi Piotr. =C2=A0Some answers inline below= ...<br> <div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote"><div class=3D= "">On Fri, Aug 29, 2014 at 10:38 AM, Piotr Klibert <span dir=3D"ltr"><<a= href=3D"mailto:[email protected]" target=3D"_blank" class=3D"crem= ed">[email protected]</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex">Hello list,<br> <br> Following recent HN submissions about OpenDylan I decided to take a closer = look<br> at the language. I wanted to learn it for a few years now, but when I last<= br> checked (yeards ago) the documentation was severly lacking. I'm very gl= ad this<br> improved.<br> <br> The first thing I decided to write was a simple "make http request&quo= t; script, as<br> usual for me. I encountered a couple of problems, which I'm sure you= 9;ll be able<br> to answer immediately, but which I wasn't able to figure out yet. I sho= uld<br> mention that I'm working with opendylan-2013.2-x86_64-linux from offici= al<br> download page and with http library from <a href=3D"https://github.com/dyla= n-lang/http" target=3D"_blank" class=3D"cremed">https://github.com/dylan-la= ng/http</a><br> <br> First, I'd like to get a list of headers out of response. I know I can = check for<br> a specific header with<br> <br> =C2=A0 =C2=A0 element(response.raw-headers, "connection", default= : #f)<br> <br> and that I can iterate over headers values with for, but I found no way of<= br> getting the list of keys for <header-table>. I read bits of table.dyl= an, and<br> noticed <vector-table> class and further entry-key method, but these = seem to be<br> internal and not exported.<br></blockquote><div><br></div></div><div>You ca= n get the keys for any collection with key-sequence.</div><div><a href=3D"h= ttp://opendylan.org/books/drm/Collection_Operations#key-sequence" target=3D= "_blank" class=3D"cremed">http://opendylan.org/books/drm/Collection_Operati= ons#key-sequence</a><br> </div><div><br></div><div>If I recall correctly you can also get a header v= alue with</div><div>=C2=A0 <font face=3D"courier new, monospace">element(re= sponse, "Connection", default: #f)</font></div><div>because the r= esponse is an instance of <message-headers-mixin>.</div> <div class=3D""> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px = 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-l= eft-style:solid;padding-left:1ex"> <br> <br> Another thing: when the program terminates due to an error on runtime I get= <br> error message, like for example:<br> <br> =C2=A0 =C2=A0 "connection" is not present as a key for {<heade= r-table>: size 1}.<br> <br> but that's all I see. Compared to other languages I'm used to worki= ng with it's<br> ascetic, to say the least. I'm not asking for a full stacktrace, but a = file and<br> line where the error originates would be a huge help already.<br></blockquo= te><div><br></div></div><div>Debuggability could certainly be better. =C2= =A0Right now the best you can do is use gdb and you'll see mangled Dyla= n names. =C2=A0On OS X you can use lldb and there's a name demangler.</= div> <div><a href=3D"http://opendylan.org/documentation/getting-started-cli/debu= gging-with-gdb-lldb.html" target=3D"_blank" class=3D"cremed">http://opendyl= an.org/documentation/getting-started-cli/debugging-with-gdb-lldb.html</a><b= r> </div><div class=3D""><div>=C2=A0</div><blockquote class=3D"gmail_quote" st= yle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb= (204,204,204);border-left-style:solid;padding-left:1ex"> <br> Further, when the program crashes, I see a<br> <br> =C2=A0 =C2=A0 Breaking into debugger.<br> <br> message. Am I correct in suspecting that this is something only available o= n<br> some platforms, and not available for me on Linux?<br></blockquote><div><br= ></div></div><div>See above.</div><div class=3D""><div>=C2=A0</div><blockqu= ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-wid= th:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-l= eft:1ex"> <br> <br> Another question involves logging. In http-common I noticed<br> <br> =C2=A0 =C2=A0 define variable *debug-reads?* =3D #f;<br> <br> - is there any way of setting this variable from my own code? This:<br> <br> =C2=A0 =C2=A0 *debug-reads?* :=3D #f;<br></blockquote><div><br></div></div>= <div>That was intended for debugging the http code itself and so isn't = exported. =C2=A0(It should be removed.)</div><div class=3D""><div>=C2=A0</d= iv><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bord= er-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:soli= d;padding-left:1ex"> <br> doesn't work and the compiler complains about an undefined binding.<br> <br> Similarly, in both http-client and http-common there are loggers defined, l= ike<br> this:<br> <br> =C2=A0 =C2=A0 define thread variable *http-common-log* :: <logger><br= > =C2=A0 =C2=A0 =C2=A0 =3D make(<logger>,<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name: "http.common&quo= t;,<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0targets: list($stdout-log-t= arget),<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0level: $info-level);<br> <br> how can I adjust the level of the loggers to something else than the defaul= t?<br> When I try to assign to *http-common-log*.level I get the error about the n= ot<br> being level-setter, which makes me suspect that logger instances should be<= br> immutable. But then I'm back to the previous question, where I can'= t reassign<br> module-level variable from outside the module...<br></blockquote><div><br><= /div></div><div>Although the init keyword for a logger is level:, the acces= sors are log-level and log-level-setter. =C2=A0You should be able to say</d= iv> <div> <br></div><div><font face=3D"courier new, monospace">*http-common-log*.log-= level :=3D $trace-level;</font></div><div><br></div><div>You could also reb= ind *http-common-log* like this:</div><div><br></div><div><font face=3D"cou= rier new, monospace">dynamic-bind (*http-common-log* =3D your-logger)</font= ></div> <div><font face=3D"courier new, monospace">=C2=A0 http-get(url, ...)</font>= </div><div><font face=3D"courier new, monospace">end</font></div><div>=C2= =A0</div><div>Looking at the logging code now, I see the naming is pretty c= onfusing since both the log- and logger- prefixes are used. =C2=A0I'll = look at cleaning that up.</div> </div></div></div></blockquote><div><br></div><div>FYI: Naming made more sa= ne by this pull request:=C2=A0<a href=3D"https://github.com/dylan-lang/logg= ing/pull/8/files">https://github.com/dylan-lang/logging/pull/8/files</a></d= iv> <div><br></div><div>I haven't yet updated http code to use it.</div><di= v>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px= 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left= -style:solid;padding-left:1ex"> <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote"> <div><br></div><div>Keep the reports coming. =C2=A0:-)</div><span class=3D"= "><font color=3D"#888888"><div>-Carl</div></font></span><div class=3D""><di= v><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0= .8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-s= tyle:solid;padding-left:1ex"> <br> Ok, that's it for now. I will probably come back with more questions so= on :)<br> <br> <br> Best regards,<br> Piotr Klibert<br> _______________________________________________<br> hackers mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank" class=3D"c= remed">[email protected]</a><br> <a href=3D"https://lists.opendylan.org/mailman/listinfo/hackers" target=3D"= _blank" class=3D"cremed">https://lists.opendylan.org/mailman/listinfo/hacke= rs</a><br> </blockquote></div></div><br></div></div> </blockquote></div><br></div></div> --001a1133a6aeef063205023166f0-- --===============1559161183== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ hackers mailing list [email protected] https://lists.opendylan.org/mailman/listinfo/hackers --===============1559161183==--