modifying log level at run-time

111 views
Skip to first unread message

Adam

unread,
Aug 19, 2014, 3:20:35 PM8/19/14
to akka...@googlegroups.com
Hi,

I know Akka's configuration does not get reloaded at run-time (see here).
It is however quite a common use case for logger settings to be re-loadable at run-time.
Is there any way to achieve this?

Will Sargent

unread,
Aug 19, 2014, 5:07:05 PM8/19/14
to akka...@googlegroups.com
Yes, you can use SLF4JLogger, then cast to Logback and change the log level there.


Will Sargent
Consultant, Professional Services
Typesafe, the company behind Play Framework, Akka and Scala


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Will Sargent

unread,
Aug 19, 2014, 5:09:11 PM8/19/14
to akka...@googlegroups.com
Or, if you just want a reloadable runtime, you can tell Logback to watch for changes to the logging file using autoScan:



Will Sargent
Consultant, Professional Services
Typesafe, the company behind Play Framework, Akka and Scala


√iktor Ҡlang

unread,
Aug 19, 2014, 5:18:43 PM8/19/14
to Akka User List
or:

defsetLogLevel(level: LogLevel)Unit

Change log level: default loggers (i.e. from configuration file) are subscribed/unsubscribed as necessary so that they listen to all levels which are at least as severe as the given one. See object Logging for more information.

NOTE: if the StandardOutLogger is configured also as normal logger, it will not participate in the automatic management of log level subscriptions!



--
Cheers,

Adam

unread,
Aug 28, 2014, 7:35:33 AM8/28/14
to akka...@googlegroups.com
Hi,

One more follow up question.
When using the setting advised by the documentation for this scenario (http://doc.akka.io/docs/akka/snapshot/java/logging.html#SLF4J) the only real gap from what I need is that with akka.logLevel set to DEBUG and with the SLF4J binding configured to INFO, writing code like this:

 
   if (logger.isDebugEnabled()) {
      logger
.error("This is an error");
   
}


Will cause the above error to be logged, which isn't really what I'd expect to happen (I'd expect nothing to be logged).

If I were to use the event bus to circumvent this, it would probably resolve many cases of this happening (depending on how often this code is reached and how often I’d be polling the configuration), but it wouldn’t really make this go away.
So should I really go down this road, or is this really a bug that could be fixed in Akka?
Or maybe this is actually an intended limitation?

Patrik Nordwall

unread,
Aug 29, 2014, 2:44:02 AM8/29/14
to akka...@googlegroups.com
Using log.isDebugEnabled followed by log.error is a bit strange in my opinion.

Anyway, what you are looking for was solved here: https://github.com/akka/akka/pull/15413

It is not released yet.

Cheers,
Patrik


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

אדם חונן

unread,
Aug 29, 2014, 3:44:32 AM8/29/14
to akka...@googlegroups.com
Ah good.
That makes sense - I was trying to see in the latest source code where this stems for and simply couldn't figure it out...


BTW, I agree it is a bit strange.
I only did it because I wanted to get a stack trace and the debug methods don't allow supplying an exception.
But indeed I've replaced it with a string parameter that details the stack trace, so I can use a debug method, which makes both the source code and the logs more readable.

Anyway thanks a lot!


You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/zTzAKjkQ5tc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Patrik Nordwall

unread,
Aug 29, 2014, 3:45:59 AM8/29/14
to akka...@googlegroups.com
On Fri, Aug 29, 2014 at 9:44 AM, אדם חונן <adam...@gmail.com> wrote:
Ah good.
That makes sense - I was trying to see in the latest source code where this stems for and simply couldn't figure it out...


BTW, I agree it is a bit strange.
I only did it because I wanted to get a stack trace and the debug methods don't allow supplying an exception.
But indeed I've replaced it with a string parameter that details the stack trace, so I can use a debug method, which makes both the source code and the logs more readable.

Sounds good 


Anyway thanks a lot!

You're welcome. 

/Patrik
Reply all
Reply to author
Forward
0 new messages