clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / Atom feed
From: "Iñaki Baz Castillo" <ibc@aliax.net>
To: clogger@librelist.com
Subject: Re: How to log a variable value? [SOLVED]
Date: Wed, 16 Dec 2009 16:21:45 +0100
Message-ID: <200912161621.45653.ibc@aliax.net> (raw)
In-Reply-To: <200912092311.29760.ibc@aliax.net>

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>

           reply index

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <200912092311.29760.ibc@aliax.net>]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://bogomips.org/clogger/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200912161621.45653.ibc@aliax.net \
    --to=ibc@aliax.net \
    --cc=clogger@librelist.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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

Example config snippet for mirrors

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/

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