clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
* Re: How to log a variable value? [SOLVED]
       [not found]   ` <200912092311.29760.ibc@aliax.net>
@ 2009-12-16 15:21     ` Iñaki Baz Castillo
  0 siblings, 0 replies; 1+ messages in thread
From: Iñaki Baz Castillo @ 2009-12-16 15:21 UTC (permalink / raw)
  To: clogger

El Miércoles, 9 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> El Domingo, 6 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> > El Sábado, 5 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> > > El Sábado, 5 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> > > > If not, perhaps I could use $remote_user, but I don't know where
> > > > Clogger reads that value from. How could I manually set a value for
> > > > $remote_user so Clogger logs it?
> > >
> > > By  inspecting Rack auth files I expect that I just must give value to
> > > env["REMOTE_USER"].
> >
> > Unfortunatelly it's not valid for me. Clogger requires to have the value
> > of env["REMOTE_USER"] already set, so it expects the usage of Rack Auth
> > application (which is runned at the beginning).
> >
> > However I don't use Rack auth, neither other authentication way. My
> > server just receives the request with a header like:
> >   X-Identity: "IBC <sip:ibc@aliax.net>"
> > so in the log I want to show "sip:ibc@aliax.net" (and not the entire
> > value of this header).
> >
> > I build the Rack app by doing the following:
> >
> > -------------------------
> >
> > :Rack::Builder.new do
> >
> >   use ::Clogger,
> >
> >       :logger => ::File.open(XXXXXXXXX, "ab"),
> >       :
> >                  :format => "[$time_local{%b %d %Y %H:%M:%S}]
> >                  : $remote_user $ip
> >
> >                  \"$request_method $request_uri\" $status
> > $body_bytes_sent bytes $request_time{4} sec".freeze
> >
> >   map "/", &::MyProject::handle_request
> >
> > end
> > --------------------------
> >
> >
> > In this way I cannot set the value for env["REMOTE_USER"] before using
> >  Clogger because I parse the content of "X-Identity" header into the
> > method MyProject::handle_request.
> >
> > Any help please? Thanks a lot.

ok, after understanding how env is handled by some middlewares (using "merge") 
I've found the solution:

  use Init
  use Clogger
  map "/", MyApp

so in Init I do:

      def call(env)
        # Create env["REMOTE_USER"] so it can be latter replaced
         (String#replaced) by the main application and Rack would log it.
        env["REMOTE_USER"] = ""
        @app.call(env)
      end


and later in MyApp I set value:

  env["REMOTE_USER"].replace("my value")


In this way my modified env["REMOTE_USER"] value is visible for Clogger. :)


Regards.

-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200912052313.45494.ibc@aliax.net>
     [not found] ` <200912060005.27969.ibc@aliax.net>
     [not found]   ` <200912092311.29760.ibc@aliax.net>
2009-12-16 15:21     ` How to log a variable value? [SOLVED] Iñaki Baz Castillo

clogger RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/clogger-public
	git clone --mirror http://ou63pmih66umazou.onion/clogger-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.clogger
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox