pedestal

hlship 2020-01-10T01:06:57.009700Z

Q about io.pedestal.log; I believe this line of code: https://github.com/pedestal/pedestal/blob/master/log/src/io/pedestal/log.clj#L247 may be broken. It attempts to use the override-logger as a LoggerSource instance, rather than a function that is passed a string and returns a LoggerSource. Unless I'm missing something, you can't currently use

-Dio.pedestal.log.overrideLogger=my.namespace/create-logger-source
because you get a runtime exception trying to apply the LoggerSource protocol to a Var. Am I missing something?

hlship 2020-01-10T01:08:32.010700Z

My scenario is to redirect code writing to io.pedestal.log/log to instead invoke our legacy, in-house logging framework.

hlship 2020-01-10T01:09:43.011900Z

I believe the overrideLogger system property works when used w/ log/info, log/debug, etc., as they go through the private log-expr function: https://github.com/pedestal/pedestal/blob/master/log/src/io/pedestal/log.clj#L275 ... which does what you'd expect; treat the override-logger as a function that generates LoggerSource instances.

2020-01-10T14:35:01.012700Z

@hlship, yep that looks like a bug to me. I’ll file an issue and address

2020-01-10T15:40:35.012800Z

Fix landed on master. Thanks for reporting!

hlship 2020-01-10T18:29:34.013Z

There may be more to it than that.

hlship 2020-01-10T18:29:50.013200Z

I copied master's log.clj to my project and am trying to use it.

hlship 2020-01-10T18:30:26.013400Z

But I think there's an issue in actually using it.

hlship 2020-01-10T18:31:11.013600Z

Because my defaultLogger function needs to require io.pedestal.log so that it can implement the LoggerSource protocol.

hlship 2020-01-10T18:33:27.013800Z

But https://github.com/pedestal/pedestal/blob/621b6896aab6582499e0076bd9c73d5aeb01dae9/log/src/io/pedestal/log.clj#L196 needs the Var in question to resolvable when io.pedestal.log is loading, resulting in a loop.

hlship 2020-01-10T18:34:10.014100Z

Perhaps use a delay to break the cycle?

hlship 2020-01-10T18:34:36.014300Z

Or move LoggerSource protocol to a separate namespace.

hlship 2020-01-10T18:35:31.014500Z

I can do some trickery with alter-var-root! to work around this, I hope.

2020-01-10T18:55:15.014700Z

@hlship here’s one way to address that. I’ll be honest, I’d rather the protocol live in a separate ns but unfortunately that’s not how it was implemented. This method of overriding is also used for tracing and has been a source of confusion as well. I’m going to chat with Paul about it.

hlship 2020-01-10T18:59:03.015100Z

Fortunately, override-logger is public, so I can just alter-var-root it in my server startup code, which should catch most of what I need.

2020-01-10T19:03:41.015300Z

Ok. I’ll work on clarifying how this is intended to be done in the docs. It’s come up a number of times.

hlship 2020-01-10T19:08:04.015500Z

I could work on a PR that made use of a delay, but it's problematic because override-logger is public.

hlship 2020-01-10T19:08:30.015700Z

Then again, it seems like no one could possibly be using it via the sysprop/envvar at all.

2020-01-10T19:19:07.015900Z

FWIW, spoke to Paul and he stated that what I posted is the intended setup, albeit other methods could work as well.

hlship 2020-01-10T19:26:08.016100Z

It just feels a bit broken in a way that's all but impossible to fix in a backwards compatible way. Logging ... it'll always bite your ass.

2020-01-10T19:29:37.016300Z

yeah, in retrospect, splitting out the protocol would have been ideal.

hlship 2020-01-10T19:32:05.016500Z

Is there a way to move it to a new namespace but alias the protocol (and protocol methods) back into io.pedestal.log?

2020-01-10T19:37:03.016700Z

I don’t know for sure but I doubt it

hlship 2020-01-10T19:42:10.016900Z

I'm still struggling with the above approach; I think AOT is getting in the way, and (for the time being) need AOT my server.

2020-01-10T19:44:45.017100Z

Hm could be

2020-01-10T19:49:08.017300Z

I uberjar my sample with :aot :all and it seems to work. Wierd.

hlship 2020-01-10T19:54:03.017500Z

I was getting ClassNotFoundException for LoggerSource. Not sure what's up with that.