Re: Some newbie questions: http-client, logging.
Carl Gay <[email protected]> Sun, 31 Aug 2014 00:55:32 -0400
| Newsgroups | gmane.comp.lang.dylan.gwydion.devel |
|---|---|
| Message-ID | <CALekcH3r8VtE5CX3TC+gbjC0y9xY4vvrwE-j2r3VMUvAoUbzqA@mail.gmail.com> |
--===============1529690331== Content-Type: multipart/alternative; boundary=089e0160a638344f6c0501e5b241 --089e0160a638344f6c0501e5b241 Content-Type: text/plain; charset=UTF-8 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. 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 > --089e0160a638344f6c0501e5b241 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Hi Piotr. =C2=A0Some answers inline below...<br><div class= =3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Fri, Aug 29, 2014 at= 10:38 AM, Piotr Klibert <span dir=3D"ltr"><<a href=3D"mailto:piotr.klib= [email protected]" target=3D"_blank">[email protected]</a>></spa= n> 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">https://github.com/dylan-lang/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>You can get = the keys for any collection with key-sequence.</div><div><a href=3D"http://= opendylan.org/books/drm/Collection_Operations#key-sequence">http://opendyla= n.org/books/drm/Collection_Operations#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>=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>Debuggability could certainly be better. =C2=A0Right= now the best you can do is use gdb and you'll see mangled Dylan 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">http://opendylan.org/documentation/getting-starte= d-cli/debugging-with-gdb-lldb.html</a><br></div><div>=C2=A0</div><blockquot= e 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-lef= t: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>See above.</div><div>=C2=A0</div><blockquote class=3D"gmail_quo= te" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-col= or:rgb(204,204,204);border-left-style:solid;padding-left: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>T= hat was intended for debugging the http code itself and so isn't export= ed. =C2=A0(It should be removed.)</div><div>=C2=A0</div><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;bo= rder-left-color:rgb(204,204,204);border-left-style:solid;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>Although the init keyword for a logger is level:, the accessors a= re log-level and log-level-setter. =C2=A0You should be able to say</div><di= v> <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><br></div><div>Keep the reports coming. =C2=A0:-)</div><div>-Carl</div= ><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0= px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-le= ft-style: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]">[email protected]<= /a><br> <a href=3D"https://lists.opendylan.org/mailman/listinfo/hackers" target=3D"= _blank">https://lists.opendylan.org/mailman/listinfo/hackers</a><br> </blockquote></div><br></div></div> --089e0160a638344f6c0501e5b241-- --===============1529690331== 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 --===============1529690331==--