clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / 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; only message 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] only message in thread

only message in thread, other threads:[~2009-12-16 15:22 UTC | newest]

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

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/clogger.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).