Setting Jekyll.logger log_level in Tag Plugin

I can send a message to the Jekyll.logger from a tag plugin like this: "Hello, world"

But I cannot seem to adjust or set the logging level. The following causes no error and has no effect (when invoked prior to generating log output):

Jekyll.logger.adjust_verbosity(:quiet => true)

I also tried adding the following to _config.yml to no effect:

quiet: true

Suggestions? I would be happy if I could globally adjust a singleton log_level, even better if I could configure a log_level for my plugin separately from other aspects of Jekyll.

Technically, plugins cannot change log levels continuously or separately.
To set levels globally, use --verbose / -V and --quiet / -q at the time of invocation:

bundle exec jekyll build --verbose
bundle exec jekyll build --quiet

Thanks, @ashmaroli. Actually, I just realized that the reason some log lines always appeared is because I used puts to generate output (oops!). After I replaced them with proper log statements I was able to adjust the log level in my plugin with:

Jekyll.logger.adjust_verbosity(:quiet => true)

If this is unexpected, then please do not consider it a bug :slight_smile:

I then tried the following, but it did not do anything:

Jekyll.logger.adjust_verbosity(:warn => true)

Looks like I will have to set up my own logger in my plugin, instead of using Jekyll’s logger.

module SubEntities
  # See
  @@log =
  @@log.level = Logger::WARN
  @@log.progname = 'subentities_menu'
  @@log.formatter = proc { |severity, datetime, progname, msg| "#{severity} #{progname}: #{msg}\n" }

  def self.log

  # Used like this: "msg"
   SubEntities.log.warn "msg".yellow

When you say, did not do anything, how did you come to that conclusion? what did you expect to see? Were you specifically monitoring the STDOUT or the STDERR channels?

If all you want is to output yellow text from your plugin, you could write wrapper method instead:

def log_warning(msg)
  Jekyll.logger.warn "[My Plugin]:", msg

However, the warning is output into the STDERR channel.
To output warnings into STDOUT, you’ll have to fashion a custom logger like you contemplated.

Just published a blog post about this and provided an acknowledgement to you.

Thanks for your help!

Thanks for the acknowledgement, though I would not say it is impossible to adjust log levels even supposedly. The presence of a public method that allows you to do so contradicts the statement.

What I meant to say in the earlier comment was regarding switching log levels continuously
i.e. output part of the build with :debug level, then switch to :warn level and then switch to :info level and then back to :debug level.
(This is my understanding of the core logger implementation. You’re welcome to correct me if I misunderstood the code.)

Good point re. “supposedly”. Will rephrase. :slight_smile:

1 Like

I wrote a LogFactory class and added a section to the article telling readers how to download and use it in Jekyll plugins.