Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce logging to main output in build and add testbed log archive #395

Merged
merged 6 commits into from
Nov 7, 2024

Conversation

peterbroadhurst
Copy link
Contributor

@peterbroadhurst peterbroadhurst commented Nov 6, 2024

Proposed changes

Note I attempted lots of ways to get log4j2 to do rolling file based logging, and after much frustration and reading of examples I gave up - sorry 🙇

... some bundle of code I gave up on, with multiple different approached embedded, none of which either:

  • switched off console logging
  • made anything appear in the files it started creating
        if (logConfig.output().equals("file") && logConfig.file() != null) {
            ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
            builder.setStatusLevel(level);
            builder.setConfigurationName("DefaultLogger");
            var triggeringPolicy = builder.newComponent("Policies")
                    .addComponent(builder.newComponent("CronTriggeringPolicy").addAttribute("schedule", "0 0 0 * * ?"))
                    .addComponent(builder.newComponent("SizeBasedTriggeringPolicy").addAttribute("size", "100M"));
            LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout")
                    .addAttribute("pattern", "%d [%t] %-5level: %msg%n");
            var appenderBuilder = builder.newAppender("rolling", "RollingFile")
                    .addAttribute("fileName", "%s.jlog".formatted(logConfig.file().filename()))
                    .addAttribute("filePattern", "%s.jlog-%%d{MM-dd-yy}.log.gz".formatted(logConfig.file().filename()))
                    .add(layoutBuilder)
                    .addComponent(triggeringPolicy);
            builder.add(appenderBuilder);
            builder.add( builder.newRootLogger( level )
                    .add( builder.newAppenderRef( "rolling" ) ) );
            Configurator.reconfigure(builder.build());
        }

        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        final Configuration config = ctx.getConfiguration();
        for (var appender :  config.getRootLogger().getAppenderRefs()) {
            config.getRootLogger().removeAppender(appender.getRef());
        }
        ctx.updateLoggers();

        Configurator.setAllLevels("io.kaleido.paladin", level);

Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
@peterbroadhurst peterbroadhurst changed the title Upload logs Reduce logging to main output in build and add testbed log archive Nov 6, 2024
@peterbroadhurst peterbroadhurst marked this pull request as ready for review November 6, 2024 12:40

- name: Upload logs
uses: actions/upload-artifact@v4
if: always()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I believe so, otherwise on failure (when we need the logs most), the step is skipped

@peterbroadhurst peterbroadhurst merged commit 4ce4dae into main Nov 7, 2024
3 checks passed
@peterbroadhurst peterbroadhurst deleted the build-output branch November 7, 2024 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants