7 Replies Latest reply on May 16, 2016 11:52 AM by jamezp

    MDC specfic logger?

    nickarls

      Hi,

       

          We have a scenario where it would be handy to log an entire user session to a separate file. Is this possible with WildFly (e.g. based on a value placed in the MDC) or is there some base class that could serve as a starting point for such a logger?

       

      I noticed that rolling-file-appenders have a rollover-policy class but I guess there is no "random-access" log file selection policy class anwhere?

       

      Thanks in advance,

      Nik

        • 1. Re: MDC specfic logger?
          jamezp

          There's currently not a way to do this. You might be able to write a custom-handler to do it though.

           

          Do you want to be able to filter messages on a logger to log to different handlers?

           

          --

          James R. Perkins

          • 2. Re: MDC specfic logger?
            nickarls

            I can think of multiple scenarios where grouping would be handy

             

            • Collecting a single user session into a file
            • Collect a single host activity to a file
            • Collect the lifecycle of an entity (e.g. a long-lived order or process) into a single file

             

            Something in the line of a normal file appender but it would have some sort of LogFilePolicyClass that would be responsible for returning the correct log file to write to (creating it if it doesn't exist). There might be some lookup table or cache in order to avoid performance problems due to constant file-switching(?). Of course most of this stuff is doable with various log analyzers or general grepping but it could still be useful.

            • 3. Re: MDC specfic logger?
              nickarls
              • 4. Re: MDC specfic logger?
                jamezp

                Okay makes sense. It's something to consider for sure. The context switching could be a bit expensive, but it could also be wrapped in a async-handler.

                 

                For a log collector you could use something like the ELK stack which I think will allow filtering based on MDC entries. If you haven't seen it here's a small post on how to configure WildFly for the ELK stack Centralized Logging for WildFly with the ELK Stack · WildFly.

                 

                --

                James R. Perkins

                1 of 1 people found this helpful
                • 5. Re: MDC specfic logger?
                  nickarls

                  My company is about to start a project where we get paid for contributing to Open Source projects so I might have a stab at this.

                   

                  I noticed that the WriterHandler has a preWrite method. If the logger class holds a MDC-value -> log file mapping, this could be used for file selection, right?

                  • 6. Re: MDC specfic logger?
                    khantariquealam

                    Hello Nicklas,

                     

                    We are able to achieve similar requirement in Wildfly 8.2.1 (related to value put in MDC).

                     

                    Hope this link can help to fulfill your requirement https://developer.jboss.org/message/946929#946929

                     

                    -Tarique

                    • 7. Re: MDC specfic logger?
                      jamezp

                      Yeah that would work and thanks! Just ping me if you have any questions along the way.

                       

                      --

                      James R. Perkins