Skip to content

Commit

Permalink
improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszm committed Apr 23, 2019
1 parent f4b937c commit e416400
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions cli/src/main/java/com/mrv/yangtools/codegen/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -109,6 +110,13 @@ protected void generate() throws IOException, ReactorException {
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.yang");

final SchemaContext context = buildSchemaContext(yangDir, p -> matcher.matches(p.getFileName()));

if(log.isInfoEnabled()) {
String modulesSting = context.getModules().stream().map(ModuleIdentifier::getName).collect(Collectors.joining(", "));

log.info("Modules found in the {} are {}", yangDir, modulesSting);
}

final Set<Module> toGenerate = context.getModules().stream().filter(m -> modules == null || modules.contains(m.getName()))
.collect(Collectors.toSet());

Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</encoder>
</appender>

<logger name="root" level="WARN">
<logger name="root" level="INFO">
<appender-ref ref="STDERR" />
</logger>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@ public enum Strategy {optimizing, unpacking}
public SwaggerGenerator(SchemaContext ctx, Set<org.opendaylight.yangtools.yang.model.api.Module> modulesToGenerate) {
Objects.requireNonNull(ctx);
Objects.requireNonNull(modulesToGenerate);
if(modulesToGenerate.isEmpty()) throw new IllegalStateException("No modules to generate has been specified");

if(ctx.getModules().isEmpty()) {
log.error("No modules found in the context.");
throw new IllegalStateException("No modules found in the context.");
}
if(modulesToGenerate.isEmpty()) {
log.error("No modules has been specified for swagger generation");
if(log.isInfoEnabled()) {
String msg = ctx.getModules().stream().map(ModuleIdentifier::getName).collect(Collectors.joining(", "));
log.info("Modules in the context are: {}", msg);
}
throw new IllegalStateException("No modules to generate has been specified");
}
this.ctx = ctx;
this.modules = modulesToGenerate;
target = new Swagger();
Expand Down Expand Up @@ -282,10 +294,7 @@ public Swagger generate() {
ArrayList<String> mNames = new ArrayList<>();
ArrayList<String> mDescs = new ArrayList<>();

if(ctx.getModules().isEmpty() || modules.isEmpty()) {
log.info("No modules found to be transformed into swagger definition");
return target;
}


log.info("Generating swagger for yang modules: {}",
modules.stream().map(ModuleIdentifier::getName).collect(Collectors.joining(",","[", "]")));
Expand Down

0 comments on commit e416400

Please sign in to comment.