Forge Home

log4j

Manages log4j configuration files

10,754 downloads

8,934 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 1.1.0 (latest)
  • 1.0.2
  • 1.0.1
  • 1.0.0
  • 0.0.1
released Jun 2nd 2015
This version is compatible with:
  • ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'danielgil-log4j', '1.1.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add danielgil-log4j
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install danielgil-log4j --version 1.1.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download
Tags: java, log4j

Documentation

danielgil/log4j — version 1.1.0 Jun 2nd 2015

puppet-log4j

This is a puppet module to manage your log4j2 configuration programatically. It provides types for loggers and appenders so that your final log4j config can be generated either from Hiera data or from Puppet manifests.

Installation

From the Forge:

puppet module install danielgil-log4j

Cloning from Github into your $MODULEPATH directory, e.g.:

git clone https://github.com/danielgil/log4j.git /etc/puppetlabs/puppet/modules/log4j

Usage (from Hiera)

To generate a log4j.xml directly from a Yaml file, you can use a structure of nested hashes:

  1. Top level: configuration file paths, e.g. /tmp/config.xml. This element has two required elements, loggers and appenders, plus the normal optional parameters of the log4j::configfile class.
  2. Loggers is a hash of hashes representing each logger. See the parameters of log4j::logger.
  3. Appenders is a hash of hashes representing each appender. Notice the type parameter can be console, file or rollingfile.

Full example:

---
log4j::data:
    '/tmp/config.xml':
        loggers:
            my.class:
                level     : 'INFO'
                additivity: true
            other.class:
                level     : 'ERROR'
                additivity: true
        appenders:
            appender1:
                type    : 'file'
                filename: '/opt/otherapp/logs/access.log'
                follow  : true
  '/opt/otherapp.xml':
        user     : tomcat
        group    : tomcat
        mode     : 0644
        loggers  :
            my.awesome.class:
                level     : 'INFO'
                additivity: true
        appenders:
            someappender:
                type  : 'console'
                layout: '%m%n'
            anotherappender:
                type          : 'rollingfile'
                layout        : '%d{ISO8601} [%t] %-2p %c{1} %m%n'
                policy_startup: false
                policy_size   : '200 Mb'
            anotherappender:
                type          : 'gelf'
                layout        : '%d{ISO8601} [%t] %-2p %c{1} %m%n'
                protocol      : TCP
                server        : someserver.somedomain
                port          : 1234

Usage (from Puppet Manifests)

Config Skeleton

Create skeleton configuration files with log4j::configfile.

Minimal:

log4j::configfile {'/tmp/config.xml':}

Full:

log4j::configfile {'/tmp/config.xml':
  user            => 'root',
  group           => 'root',
  mode            => '0644',
  monitorInterval => '40',
  rootLevel       => 'INFO',
  replace         => false,
  xmllint         => true,
}

The xmllint parameter, if set to true, will install libxml2 and use it to format the resulting log4j configuration file.

Add Appenders

The File appender writes to a file. Only path and filename are required.

log4j::appenders::file {'somefile':
  path     => $xmlpath,
  filename => '/tmp/somelog.log',
  append               => true,
  bufferedio           => true,
  buffersize           => '8192',
  immediateflush       => true,
  locking              => false,
  ignoreexceptions     => true,
  layout   => '%d{ISO8601} [%t] %-2p %c{1} %m%n',
}

The Console appender writes to either the system's standard output or error. Only path is required.

log4j::appenders::console {'stdout':
  path     => '/tmp/config.xml,
  follow   => true,
  target   => 'SYSTEM_ERR',
  ignoreexceptions => true,
  layout   => '%m%n',
}

The RollingFile appender is similar to the File, except that you can control when the file is rolled using the 3 policy parameters, and how the file is renamed using the 4 strategy parameters.

It's worth noting that the policy parameters can be combined.

log4j::appenders::rollingfile {'rollbaby':
  path                 => '/tmp/config.xml,
  filename             => '/tmp/somelog.log',
  append               => true,
  bufferedio           => true,
  buffersize           => '8192',
  immediateflush       => true,
  ignoreexceptions     => true,
  layout               => '%d{ISO8601} [%t] %-2p %c{1} %m%n',
  filepattern          => 'logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log',
  strategy_compression => '0',
  strategy_min         => '1',
  strategy_max         => '10',
  strategy_fileindex   => 'max',
  policy_startup       => true,
  policy_size          => '',
  policy_time          => '',
}

The GELF appender connects to a Graylog server on a GELF TCP or GELF UDP input. Only path is required.

log4j::appenders::gelf {'example':
  path             => '/tmp/config.xml,
  protocol         => 'TCP',
  server           => 'somegraylogserver.somedomain',
  port             => '12201',
  layout           => '%m%n',
  hostname         => 'myserver.somedomain',
  additionalfields => 'key1=value1,key2=value2',
}

Add Loggers

To To add a logger for a specific class, use the name of the class as the name of the logger.

log4j::logger {'my.class':
  path       => '/tmp/config.xml',
  level      => 'INFO',
  additivity => true,
}

Limitations

  1. Supported appenders: Console, File, RollingFile and Gelf.
  2. For now, File and RollingFile only use PatternLayout and do not accept Filters.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D