Package org.apache.logging.log4j.core

Examples of org.apache.logging.log4j.core.LogEvent


        assertNotNull(formatters);
        final Map<String, String> mdc = new HashMap<String, String>();
        mdc.put("loginId", "Fred");
        final Throwable t = new Throwable();
        final StackTraceElement[] elements = t.getStackTrace();
        final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest", MarkerManager.getMarker("TEST"),
            Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null,
            mdc, null, "Thread1", elements[0], System.currentTimeMillis());
        final StringBuilder buf = new StringBuilder();
        for (final PatternFormatter formatter : formatters) {
            formatter.format(event, buf);
View Full Code Here


    private void testNestedPatternHighlight(final Level level, final String expectedStart) {
        final List<PatternFormatter> formatters = parser.parse(nestedPatternHighlight);
        assertNotNull(formatters);
        final Throwable t = new Throwable();
        final StackTraceElement[] stackTraceElement = t.getStackTrace();
        final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest",
                MarkerManager.getMarker("TEST"), Logger.class.getName(), level, new SimpleMessage("Hello, world"),
                null, null, null, "Thread1", /*stackTraceElement[0]*/null, System.currentTimeMillis());
        final StringBuilder buf = new StringBuilder();
        for (final PatternFormatter formatter : formatters) {
            formatter.format(event, buf);
View Full Code Here

    @Test
    public void testLocation() {
        final Timer timer = new Timer("LogEvent", LOOP_COUNT);
        timer.start();
        for (int i = 0; i < LOOP_COUNT; ++i) {
            final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                "org.apache.logging.log4j.core.impl.Log4jLogEvent",
                Level.INFO, new SimpleMessage("Hello, world!"), null);
            final StackTraceElement element = event1.getSource();
        }
        timer.stop();
        System.out.println(timer.toString());
    }
View Full Code Here

            // bypass RingBuffer and invoke Appender directly
            return false;
        }
        // LOG4J2-639: catch NPE if disruptor field was set to null after our check above
        try {
            LogEvent logEvent = event;
            if (event instanceof RingBufferLogEvent) {
                logEvent = ((RingBufferLogEvent) event).createMemento();
            }
            // Note: do NOT use the temp variable above!
            // That could result in adding a log event to the disruptor after it was shut down,
View Full Code Here

        try {
            verify(this.provider, this.connection);
            reset(this.provider, this.connection);

            final LogEvent event = createStrictMock(LogEvent.class);
            replay(this.provider, this.connection, event);

            try {
                manager.writeInternal(event);
                fail("Expected AppenderLoggingException.");
View Full Code Here

            manager.connectAndStart();

            verify(this.provider, this.connection);
            reset(this.provider, this.connection);

            final LogEvent event = createStrictMock(LogEvent.class);
            expect(this.connection.isClosed()).andReturn(true);
            replay(this.provider, this.connection, event);

            try {
                manager.writeInternal(event);
View Full Code Here

            verify(this.provider, this.connection);
            reset(this.provider, this.connection);

            final Capture<NoSQLObject<Map<String, Object>>> capture = new Capture<NoSQLObject<Map<String, Object>>>();

            final LogEvent event = createStrictMock(LogEvent.class);
            final Message message = createStrictMock(Message.class);

            expect(this.connection.isClosed()).andReturn(false);
            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDBObject>() {
                @Override
                public CouchDBObject answer() throws Throwable {
                    return new CouchDBObject();
                }
            }).atLeastOnce();
            expect(event.getLevel()).andReturn(Level.WARN);
            expect(event.getLoggerName()).andReturn("com.foo.NoSQLDbTest.testWriteInternal01");
            expect(event.getMessage()).andReturn(message).times(2);
            expect(message.getFormattedMessage()).andReturn("My formatted message 01.");
            expect(event.getSource()).andReturn(new StackTraceElement("com.foo.Bar", "testMethod01", "Bar.java", 15));
            expect(event.getMarker()).andReturn(null);
            expect(event.getThreadName()).andReturn("MyThread-A");
            expect(event.getTimeMillis()).andReturn(1234567890123L).times(2);
            expect(event.getThrown()).andReturn(null);
            expect(event.getContextMap()).andReturn(null);
            expect(event.getContextStack()).andReturn(null);
            this.connection.insertObject(capture(capture));
            expectLastCall();
            replay(this.provider, this.connection, event, message);

            manager.writeInternal(event);
View Full Code Here

            final RuntimeException exception = new RuntimeException("This is something cool!");
            final Map<String, String> context = new HashMap<String, String>();
            context.put("hello", "world");
            context.put("user", "pass");

            final LogEvent event = createStrictMock(LogEvent.class);
            final Message message = createStrictMock(Message.class);
            ThreadContext.push("message1");
            ThreadContext.push("stack2");
            final ThreadContext.ContextStack stack = ThreadContext.getImmutableStack();
            ThreadContext.clearStack();

            expect(this.connection.isClosed()).andReturn(false);
            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDBObject>() {
                @Override
                public CouchDBObject answer() throws Throwable {
                    return new CouchDBObject();
                }
            }).atLeastOnce();
            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<CouchDBObject[]>() {
                @Override
                public CouchDBObject[] answer() throws Throwable {
                    return new CouchDBObject[(Integer) getCurrentArguments()[0]];
                }
            });
            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDBObject>() {
                @Override
                public CouchDBObject answer() throws Throwable {
                    return new CouchDBObject();
                }
            }).atLeastOnce();
            expect(event.getLevel()).andReturn(Level.DEBUG);
            expect(event.getLoggerName()).andReturn("com.foo.NoSQLDbTest.testWriteInternal02");
            expect(event.getMessage()).andReturn(message).times(2);
            expect(message.getFormattedMessage()).andReturn("Another cool message 02.");
            expect(event.getSource()).andReturn(new StackTraceElement("com.bar.Foo", "anotherMethod03", "Foo.java", 9));
            expect(event.getMarker()).andReturn(MarkerManager.getMarker("LoneMarker"));
            expect(event.getThreadName()).andReturn("AnotherThread-B");
            expect(event.getTimeMillis()).andReturn(987654321564L).times(2);
            expect(event.getThrown()).andReturn(exception);
            expect(event.getContextMap()).andReturn(context);
            expect(event.getContextStack()).andReturn(stack);
            this.connection.insertObject(capture(capture));
            expectLastCall();
            replay(this.provider, this.connection, event, message);

            manager.writeInternal(event);
View Full Code Here

            final SQLException exception2 = new SQLException("This is the result.", exception1);
            final Map<String, String> context = new HashMap<String, String>();
            context.put("hello", "world");
            context.put("user", "pass");

            final LogEvent event = createStrictMock(LogEvent.class);
            final Message message = createStrictMock(Message.class);
            ThreadContext.push("message1");
            ThreadContext.push("stack2");
            final ThreadContext.ContextStack stack = ThreadContext.getImmutableStack();
            ThreadContext.clearStack();

            expect(this.connection.isClosed()).andReturn(false);
            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDBObject>() {
                @Override
                public CouchDBObject answer() throws Throwable {
                    return new CouchDBObject();
                }
            }).atLeastOnce();
            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<CouchDBObject[]>() {
                @Override
                public CouchDBObject[] answer() throws Throwable {
                    return new CouchDBObject[(Integer) getCurrentArguments()[0]];
                }
            });
            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDBObject>() {
                @Override
                public CouchDBObject answer() throws Throwable {
                    return new CouchDBObject();
                }
            }).atLeastOnce();
            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<CouchDBObject[]>() {
                @Override
                public CouchDBObject[] answer() throws Throwable {
                    return new CouchDBObject[(Integer) getCurrentArguments()[0]];
                }
            });
            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDBObject>() {
                @Override
                public CouchDBObject answer() throws Throwable {
                    return new CouchDBObject();
                }
            }).atLeastOnce();
            expect(event.getLevel()).andReturn(Level.DEBUG);
            expect(event.getLoggerName()).andReturn("com.foo.NoSQLDbTest.testWriteInternal02");
            expect(event.getMessage()).andReturn(message).times(2);
            expect(message.getFormattedMessage()).andReturn("Another cool message 02.");
            expect(event.getSource()).andReturn(new StackTraceElement("com.bar.Foo", "anotherMethod03", "Foo.java", 9));
            expect(event.getMarker()).andReturn(
                    MarkerManager.getMarker("AnotherMarker").addParents(MarkerManager.getMarker("Parent1").addParents(MarkerManager.getMarker("GrandParent1")),
                            MarkerManager.getMarker("Parent2")));
            expect(event.getThreadName()).andReturn("AnotherThread-B");
            expect(event.getTimeMillis()).andReturn(987654321564L).times(2);
            expect(event.getThrown()).andReturn(exception2);
            expect(event.getContextMap()).andReturn(context);
            expect(event.getContextStack()).andReturn(stack);
            this.connection.insertObject(capture(capture));
            expectLastCall();
            replay(this.provider, this.connection, event, message);

            manager.writeInternal(event);
View Full Code Here

        assertTrue("Appender did not start", appender.isStarted());
        long curLen = file.length();
        long prevLen = curLen;
        assertTrue("File length: " + curLen, curLen == 0);
        for (int i = 0; i < 100; ++i) {
            final LogEvent event = new Log4jLogEvent("TestLogger", null, FileAppenderTest.class.getName(), Level.INFO,
                    new SimpleMessage("Test"), null, null, null, this.getClass().getSimpleName(), null,
                    System.currentTimeMillis());
            try {
                appender.append(event);
                curLen = file.length();
View Full Code Here

TOP

Related Classes of org.apache.logging.log4j.core.LogEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.